Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么VS代码在查找pytest模块时遇到问题?_Python_Visual Studio Code_Pytest - Fatal编程技术网

Python 为什么VS代码在查找pytest模块时遇到问题?

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

我正在尝试让pytest备份并在VS代码中运行。我有一个简单的测试函数,如下所示:

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   

对可能出现的问题有何看法?

-谢谢您的反馈。此问题仍在解决中,您可以参考此内容尝试重新发现需要测试的文件。