想象一个简单的文件夹结构: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设置了它运行的路径,所以如果不手动处理它就不会出现这些类型的错误。文档也没有给出任何关于这一点的迹象......他们只是说:通常,您可以通过指向测试目录或模块来运行测试: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
提交
取消