Python 为什么VS代码在查找pytest模块时遇到问题?
我正在尝试让pytest备份并在VS代码中运行。我有一个简单的测试函数,如下所示:Python 为什么VS代码在查找pytest模块时遇到问题?,python,visual-studio-code,pytest,Python,Visual Studio Code,Pytest,我正在尝试让pytest备份并在VS代码中运行。我有一个简单的测试函数,如下所示: def test_func(): x = 1 y = 1 assert x == y 它位于根文件夹的/tests/test_sandpit.py中 在文件中可以很好地发现测试-我得到runtest和Debug test链接,它们出现在侧栏上的testexplorer中 当我点击runtest链接时,我得到以下消息: ============================= test
def test_func():
x = 1
y = 1
assert x == y
它位于根文件夹的/tests/test_sandpit.py
中
在文件中可以很好地发现测试-我得到runtest
和Debug test
链接,它们出现在侧栏上的testexplorer
中
当我点击runtest
链接时,我得到以下消息:
============================= test session starts =============================
platform win32 -- Python 3.7.7, pytest-6.1.0, py-1.9.0, pluggy-0.13.1
rootdir: c:\Users\Philip\OneDrive\Betting\Capra\Tennis\polgara
plugins: cov-2.10.1
collected 0 items
- generated xml file: C:\Users\Philip\AppData\Local\Temp\tmp-15508HvPldmuZ6HZy.xml -
============================ no tests ran in 0.00s ============================
ERROR: file or directory not found: ./tests/test_sandpit.py::test_func
这很奇怪,因为我正在单击该模块在该位置的链接
如果我从终端运行测试模块,一切正常:
platform win32 -- Python 3.7.7, pytest-6.1.0, py-1.9.0, pluggy-0.13.1 -- c:\users\philip\miniconda3\envs\capra\python.exe
cachedir: .pytest_cache
rootdir: C:\Users\Philip\OneDrive\Betting\Capra\Tennis\polgara
plugins: cov-2.10.1
collected 1 item
tests/test_sandpit.py::test_func PASSED
对可能出现的问题有何看法?-谢谢您的反馈。此问题仍在解决中,您可以参考此内容尝试重新发现需要测试的文件。