realpython / realpython/python-guide

Structuring your project guide leads to a ModuleNotFoundError in the tests module

Đang mở
#1,013 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Ngôn ngữ chính
Batchfile
Star
29.8k
Fork
5.9k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

Following this section, adding from .context import sample in my tests module gives me the following error: ModuleNotFoundError: No module named '__main__.context'; '__main__' is not a package

I was able to fix it by removing the . from from .context import sample, but I suspect that's not the ideal solution. I know that the from .context import sample is a relative import statement as described in PEP 328, but I just do not understand modules, packages, absolute and relative imports, etc. enough to say what's going on here.

I tried creating ./__init__.py and ./tests/__init__.py files, but that did not help.

Finally, I tried the following:

~> git clone git@github.com:navdeep-G/samplemod.git
~> python3 samplemod/tests/test_basic.py
Traceback (most recent call last):
  File "samplemod/tests/test_basic.py", line 3, in <module>
    from .context import sample
ModuleNotFoundError: No module named '__main__.context'; '__main__' is not a package

I'm not alone in hitting this issue. @rileyweber13 originally reported this problem a year ago.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với phần “Test Suite” được liên kết và tái hiện lệnh đã được báo cáo bằng cách sử dụng samplemod/tests/test_basic.py. Theo dõi cách tệp kiểm thử được gọi và cách import tương đối của tệp được phân giải, sau đó cập nhật hướng dẫn để quy trình thiết lập và thực thi được tài liệu hóa hoạt động mà không gặp ModuleNotFoundError đã được báo cáo.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
documentation
Loại issue
Tài liệu
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
42/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.