Python Unittest:未在 Visual Studio Code 中发现测试 [英] Python Unittest: No tests discovered in Visual Studio Code
问题描述
我正在尝试使 Visual Studio 自运行
问题是我在测试模块中使用了相对导入(from ..utils import guards
).我只是将其更改为绝对导入(from app.utils import guards
),然后一切又恢复了.
I'm trying to make the self-running feature of Visual Studio Code unit tests work. I recently made a change in the directory structure of my Python project that was previously like this:
myproje\
domain\
__init__.py
repositories\
tests\
__init__.py
guardstest.py
utils\
__init__.py
guards.py
web\
And my setup for unittest was like this:
"python.unitTest.unittestArgs": [
"-v",
"-s",
"tests",
"-p",
"*test*.py"
]
After the changes, the structure of the project was as follows:
myprojet\
app\
controllers\
__init__.py
models\
__init__.py
entities.py
enums.py
tests\
res\
image1.png
image2.png
__init__.py
guardstest.py
utils\
__init__.py
guards.py
views\
static\
templnates\
__init__.py
uml\
After that the extension does not discover my tests anymore. I've tried to change the '-s' parameter to "./app/tests"
, ".tests"
, "./tests"
, "app/tests"
, "/app/tests"
, "app.tests"
, unsuccessfully .
The problem was that I was using relative imports in the test module (from ..utils import guards
).
I just changed it to absolute import (from app.utils import guards
) and it all worked again.
这篇关于Python Unittest:未在 Visual Studio Code 中发现测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!