项目结构就像
- a.py
- unittest
- test_a.py
Run Code Online (Sandbox Code Playgroud)
py
class A():
def function_a(self):
return 'function_a'
Run Code Online (Sandbox Code Playgroud)
测试_a.py
from a import A
class TestA():
def test_a(self):
assert A().function_a() == 'function_a'
Run Code Online (Sandbox Code Playgroud)
当我使用终端 和 时set PATHONPATH=//<my-project-folder>
,可以通过 检测和测试它pytest
。然而,当我尝试在 VScode 中调试它时,它不断抛出No module named a
.
https://code.visualstudio.com/docs/python/environments#_environment-variable-definitions-file
我已经尝试过这种方法并将其放入.env
我的项目文件夹中。
.env
PYTHONPATH=C:\\Repos\\test-project
Run Code Online (Sandbox Code Playgroud)
(我在有转义和没有转义的情况下都做到了,无论如何它都不起作用。)
.vscode/setting.json
{
"python.pythonPath": "C:\\Python27\\python.exe",
"python.testing.pytestArgs": [
"unittest"
],
"python.testing.unittestEnabled": false,
"python.testing.nosetestsEnabled": false,
"python.testing.pytestEnabled": true,
"python.envFile": "${workspaceFolder}/.env",
}
Run Code Online (Sandbox Code Playgroud)