想象一個簡單的文件夾結構:my_folder/ __init__.py funcs.py tests/ test_funcs.py函數.py:def f(): return 2__init__.py:from funcs import ftest_funcs.py:from funcs import fdef test_f(): assert f() == 2這是文檔中建議的方法之一:https : //pytest.readthedocs.io/en/reorganize-docs/new-docs/user/directory_structure.html但是當我從my_folder以下位置運行 pytest 時:tests/test_funcs.py:1: in <module> from funcs import fE ModuleNotFoundError: No module named 'funcs'這很奇怪,因為我會認為它pytest設置了它運行的路徑,所以如果不手動處理它就不會出現(xiàn)這些類型的錯誤。文檔也沒有給出任何關于這一點的跡象......他們只是說:通常,您可以通過指向測試目錄或模塊來運行測試:pytest tests/test_appmodule.py # for external test dirspytest src/tests/test_appmodule.py # for inlined test dirspytest src # run tests in all below test directoriespytest # run all tests below current dir我錯過了什么?
添加回答
舉報
0/150
提交
取消