【发布时间】:2021-10-20 05:00:12
【问题描述】:
我正在尝试从脚本中运行 pytest,因此我希望它通过不带参数调用 pytest 来运行所有测试文件。但是,pytest 不会收集测试文件。
层次结构如下
project
-somedirectory
--somecode.py
-tests
--test.py
test.py如下图
def test_one():
assert True
通过 PyCharm GUI 运行 pytest 按预期工作,test.py 被收集、运行并通过。
运行pytest tests/test.py 按预期工作,test.py 被收集、运行并通过。
不带参数运行 pytest 无法按预期运行,它不会收集 test.py。
运行pwd 返回/path/to/project。
Windows 命令提示符和 PyCharm 终端的行为相同。
【问题讨论】:
-
pytest tests呢? -
默认情况下,pytest 会查找具有“_test.py”模式“test_.py”的文件,您的文件“test.py”与这些模式不匹配,因此很可能被忽略。尝试将其重命名为其他名称?以“test_foo.py”为例