我有 settings.json
{
"python.testing.unittestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.pytestEnabled": true,
"python.pythonPath": "${workspaceFolder}\\venv\\Scripts\\python.exe",
"python.testing.cwd": "${workspaceFolder}\\tests",
"launch": {
"configurations": [],
"compounds": []
},
"terminal.integrated.env.windows": {
"PYTHONPATH": "${workspaceFolder}"
},
"python.envFile": "${workspaceFolder}\\.env",
"pythonTestExplorer.testFramework": "pytest",
"python.terminal.executeInFileDir": true,
"python.testing.pytestPath": "${workspaceFolder}\\venv\\Scripts\\pytest.exe",
和 .env
WORKSPACE_FOLDER=C:\work\autotests\project
PYTHONPATH=${WORKSPACE_FOLDER}
我想为 pytest 设置“Python Test Explorer for VS code”。使用此设置资源管理器收集和运行所有测试没有任何问题,但是当我尝试运行单个测试时,我收到错误错误:找不到文件或目录。我认为这是因为资源管理器正在通过使用绝对路径(如“C:/work/project/tests”)的命令收集/运行所有测试,并使用“./tests/test_module::TestClass::test_name”等命令运行单个测试,但是我不知道。我应该怎么做才能解决这个问题?
编辑
面板内容:Output > Python
c:\work1\autotests\tms-autotest\venv\Scripts\pytest.exe --override-ini junit_family=xunit1 --rootdir c:\work1\autotests\tms-autotest --junit-xml=C:\Users\EG_BAR~1\AppData\Local\Temp\tmp-1984XJ6G3mxW2rt3.xml ./tests/action_log_api_test.py::TestGetActionTypes
cwd: c:\work1\autotests\tms-autotest\tests