我目前正在做一个Python项目,并使用pytest进行测试。我已经构建了我的项目,将测试包含在单独的目录中,并且我尝试使用
pyproject.toml
文件来指定 pytest 应发现测试文件的路径。但是,pytest 似乎无法识别 pyproject.toml
文件中指定的某些路径。
这是我的
pyproject.toml
文件的样子:
[tool.pytest.ini_options]
python_paths = ["src", "tests", "tests/Google-Calendar", "tests/Reclaim", "tests/Todoist"]
我期望 pytest 在所有指定的目录中发现并运行测试,但它没有在
"tests/Google-Calendar"
、"tests/Reclaim"
和 "tests/Todoist"
中运行测试。当我运行 pytest
时,所有测试都运行良好,但是我想通过执行 pytest filename
来单独运行它们,但我只能执行 pytest (absolute path to file)
。
我尝试过的事情:
test_*.py
或 *_test.py
)。我不确定我在这里错过了什么。有没有人遇到过类似的问题或者可以提供一些关于可能出现问题以及如何解决它的见解?
如何运行 pytest?如果您使用一种或类似的语法:
pytest app/**/test_*.py
,请尝试:pytest app/
。它帮助了我。