使用 pytest 运行单个测试方法失败(未找到)

Mat*_*shi 7 python pytest python-3.x

我正在尝试使用以下命令在 Python 3.6 上使用 pytest 运行特定的测试方法:

pytest sanity_test.py::test_check
Run Code Online (Sandbox Code Playgroud)

(如 pytest文档中所述

它失败并显示以下错误消息:

ERROR: not found: <rootdir>/tests/automation/sanity/sanity_test.py::test_check
(no name '<rootdir>/tests/automation/sanity/sanity_test.py::test_check' in any of [<DoctestModule 'tests/automation/sanity/sanity_test.py'>, <Module 
'tests/automation/sanity/sanity_test.py'>])
Run Code Online (Sandbox Code Playgroud)

当我运行整个测试文件时,测试运行正常:

pytest sanity_test.py
Run Code Online (Sandbox Code Playgroud)

当我尝试在孤立项目中运行特定方法时,它运行良好。

pytest 无法在我的项目中具体找到我的测试方法的任何原因?

该文件非常简单,如下所示:

def test_check():
    pass
Run Code Online (Sandbox Code Playgroud)

Mat*_*shi 3

感谢hoefling,我认识到--doctest-modules我的文件中有选项setup.cfg。删除此选项解决了该问题。 Hoefling针对这个问题提出了一个问题pytest