【问题标题】:PyCharm pytest GUI runs tests, terminal doesn'tPyCharm pytest GUI 运行测试,终端不运行
【发布时间】: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”为例

标签: python pycharm pytest


【解决方案1】:

默认情况下,pytest 会查找模式为“test_*.py”的文件,您的文件“test.py”与此模式不匹配,因此很可能会被忽略。尝试将其重命名为其他名称?以“test_foo.py”为例

这行得通。我没有意识到与文件和函数相关的命名约定。

【讨论】:

    猜你喜欢
    • 2020-04-25
    • 1970-01-01
    • 1970-01-01
    • 2018-01-25
    • 2020-12-18
    • 2022-11-25
    • 1970-01-01
    • 2019-06-16
    • 2018-06-01
    相关资源
    最近更新 更多