我们目前在目录pytest
中的测试上运行覆盖插件。tests
运行从我们的主代码中提取的文档测试的最简单方法是什么? --doctest-modules
不起作用(可能是因为它只是从 运行文档测试tests
)。请注意,我们希望在同一进程中包含 doctest(而不是简单地运行 的单独调用py.test
),因为我们希望在代码覆盖率中考虑 doctest。
现在它已实施:-)。
要使用,请运行py.test --doctest-modules
命令,或使用以下命令设置您的配置pytest.ini
:
$ cat pytest.ini
# content of pytest.ini
[pytest]
addopts = --doctest-modules
您可以尝试使用 pytest 的 repo 版本并粘贴会话日志吗?我认为--doctest-modules
应该选择任何 .py 文件。
在一个模块中使用 doctest 以及普通测试。对于要获取的非 doctest 测试,标准 py.test 发现机制适用:带有测试前缀的模块名称,带有测试前缀的测试函数。
看起来很老的问题,但把我的答案放在这里以防万一。