从 pycharm 使用 pytest 运行时获取空测试套件

新手上路,请多包涵

我在从 PyCharm 内部运行 pytest 测试时遇到问题

我在 C:\Temp 中名为 agents_automation_2 的文件夹中有一个文件 x_tests.py,该文件的内容是

import pytest
def test_mytest():
    assert  False

当我运行时,我得到以下输出

C:\Python36-32\python.exe “C:\Program Files\JetBrains\PyCharm 2017.3.2\helpers\pycharm_jb_pytest_runner.py” –path C:/Temp/agents_automation_2 使用参数启动 py.test C:/Temp/ C:\Temp\agents_automation_2 中的 agents_automation_2 ============================= 测试会话开始 ========== =================== 平台 win32——Python 3.6.4、pytest-3.4.2、py-1.5.2、pluggy-0.6.0 根目录:C:\ Temp\agents_automation_2, inifile: plugins: xdist-1.22.0, forked-0.2 collected 0 items ======================== 没有测试在 0.01 秒内运行=========================

但是,当我从文件夹内的常规 Windows 命令行运行时,测试运行正常

知道可能是什么问题吗?

谢谢 !!!

原文由 David Fliguer 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.9k
2 个回答

您的测试文件的名称不符合默认的 pytest 发现规则。如果将 _xtests.py 更改为 _xtest.py ,它会运行测试并按预期失败。查看 此页面 以获取有关 pytest 发现规则的更多信息。

原文由 Belerafon 发布,翻译遵循 CC BY-SA 3.0 许可协议

在我的例子中,测试类包含 init 方法,也会导致空套件。您需要做的是避免编写 init 方法。

原文由 Leo Liang 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进