VSCode中Pytest无法导入项目modules文件夹问题求助
VSCode中Pytest无法导入项目modules文件夹问题求助
我刚才还好好用着Pytest呢,VSCode里也选对了对应的conda环境,结果现在运行测试的时候,居然找不到项目目录里的modules文件夹。我的测试文件tests/test_function.py里的导入语句是这样的:
from modules.my_module import my_func
这是我的pytest.ini配置:
[pytest] testpaths = tests python_files = test_*.py addopts = -v -s filterwarnings = ignore::DeprecationWarning ignore::UserWarning ignore::RuntimeWarning
我还在VSCode的用户设置里加了这些配置:
"python.testing.pytestArgs": [ "tests", "-s" ], "python.testing.unittestEnabled": false, "python.testing.pytestEnabled": true, "python.testing.autoTestDiscoverOnSaveEnabled": true, "python.testing.pytestPath": "pytest", "python.analysis.extraPaths": ["."]
可是问题还是没解决!但奇怪的是,我在同一个conda环境的命令行里运行这个命令:
python -m pytest tests/test_function.py::test_myfunc -v
完全没问题,测试跑起来一切正常。而且VSCode5分钟前还好好的,我啥都没改啊!我已经重启过VSCode了,但还是没用。
我到底哪里错了啊?快要疯了,老是遇到这种Python导入的问题,本来该干活的时间,结果花四个小时在这上面折腾。求助!!
备注:内容来源于stack exchange,提问作者Max
相关产品推荐
相关产品推荐

