我正在尝试使 Visual Studio Code 单元测试的自运行 功能 发挥作用。我最近对我的 Python 项目的目录结构进行了更改,该目录结构以前是这样的:
myproje\
domain\
__init__.py
repositories\
tests\
__init__.py
guardstest.py
utils\
__init__.py
guards.py
web\
我的单元测试设置是这样的:
"python.unitTest.unittestArgs": [
"-v",
"-s",
"tests",
"-p",
"*test*.py"
]
改动后,项目结构如下:
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\
之后,扩展程序不再发现我的测试。 I’ve tried to change the ‘-s’ parameter to "./app/tests"
, ".tests"
, "./tests"
, "app/tests"
, "/app/tests"
, "app.tests"
,未成功。
原文由 Matheus Saraiva 发布,翻译遵循 CC BY-SA 4.0 许可协议
问题是我在测试模块中使用了相对导入(
from ..utils import guards
)。我只是将其更改为绝对导入(from app.utils import guards
)并且它再次起作用。