【问题标题】:Running pytest.main(...) does not collect tests运行 pytest.main(...) 不会收集测试
【发布时间】:2018-12-03 04:26:35
【问题描述】:

我创建了一个子文件夹,其中包含 test_*.py 文件和其他 .py 文件,其中包含正在调用的其他方法。 在项目的根目录中,我创建了main_test.py,我在其中调用pytest.main(['./subdfolder'])pytest 正在被触发,但我得到了打击输出:

============================= test session starts =============================
platform win32 -- Python 2.7.14, pytest-3.6.1, py-1.5.3, pluggy-0.6.0
rootdir: C:\PycharmProjects\TestingFramework, inifile:
plugins: tap-2.2, report-0.2.1
collected 0 items

======================== no tests ran in 0.01 seconds =========================

进程以退出代码 0 结束

【问题讨论】:

  • subdfolder 是正确的目录名称吗?
  • 是的,它的上一层是 main_test.py 我尝试调用 pytest.main()
  • 嗯,那么您必须提供a Minimal, Complete, and Verifiable example,因为我无法重现该问题 - 也许您的测试函数名称不正确,因此没有被收集?确保测试函数名称以test_ 开头。如果您有测试类,请确保它们的名称以 Test 开头。
  • 没关系,找到问题了,基本上我是在尝试使用 pytest 调用来调用 main_test.py,而实际上我应该从 main_test.py 调用 pytest.main() turn 应该被触发为常规 python 脚本,我很傻
  • 不错!考虑写一个解释问题的答案,以便帮助其他人寻找解决方案。

标签: python python-2.7 testing automation pytest


【解决方案1】:

已编辑 我发现我的命令完全错误: pytest.main() 不能从终端行调用(我正在使用 PyCharm)正确的方法是将所有代码放在 if name == "ma​​in" 以下列方式阻止:

if __name__ == "__main__":
   junit_path = '.\Reports\/Junit_' + time.strftime("%d%m%Y_%H%M%S") + '.xml'
   result_log_path = '.\Reports\/Logs\/Execution_' + 
   time.strftime("%d%m%Y_%H%M%S") + '.log'
   pytest.main(['-v', '-x','--junitxml', junit_path, '--resultlog', result_log_path])

之后使用终端命令行我可以通过调用来调用执行:

python ./<<file name>>   

【讨论】:

    猜你喜欢
    • 2018-12-31
    • 1970-01-01
    • 1970-01-01
    • 2012-10-13
    • 2012-06-19
    • 1970-01-01
    • 2014-07-26
    • 2015-02-04
    • 1970-01-01
    相关资源
    最近更新 更多