The project structure is like
- a.py
- unittest
- test_a.py
A.py
class A():
def function_a(self):
return 'function_a'
test_a.py
from a import A
class TestA():
def test_a(self):
assert A().function_a() == 'function_a'
When I use terminal and set PATHONPATH=//<my-project-folder>, it can be detected and tested via pytest. However, when I tried to debug it in VScode, it kept throwing out No module named a.
https://code.visualstudio.com/docs/python/environments#_environment-variable-definitions-file
I've tried this way and put a .env inside my project folder.
.env
PYTHONPATH=C:\\Repos\\test-project
(I did it with and without escaping, it didn't work anyway.)
.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",
}