How to make py.test run doctests as well as normal tests directory?

我们两清 提交于 2019-12-30 03:47:09

问题


We currently have py.test with the coverage plugin running over our tests in a tests directory.

What's the simplest way to also run doctests extracted from our main code? --doctest-modules doesn't work (probably since it just runs doctests from tests). Note that we want to include doctests in the same process (and not simply run a separate invocation of py.test) because we want to account for doctest in code coverage.


回答1:


Now it is implemented :-).

To use, either run py.test --doctest-modules command, or set your configuration with pytest.ini:

$ cat pytest.ini
# content of pytest.ini
[pytest]
addopts = --doctest-modules

Man page: PyTest: doctest integration for modules and test files.




回答2:


Could you try with the repo version of pytest and paste a session log? I'd think --doctest-modules should pick up any .py files.




回答3:


worked with doctest as well as with plain tests in one module. for a non-doctest test to be picked up, standard py.test discovery mechanism applies: a module name with test prefix, test function with test prefix.



来源:https://stackoverflow.com/questions/17056138/how-to-make-py-test-run-doctests-as-well-as-normal-tests-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!