How to make pytest run doctests as well as normal tests directory?

前端 未结 4 1255
南方客
南方客 2021-01-01 14:54

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

What\'s the simplest way to also run doctest

相关标签:
4条回答
  • 2021-01-01 15:22

    Looks old question but put my answer here just in case.

    • pytest only run tests in /*test*.py AFAIK and you need to customze with this behavior by the configurations, testpaths and python_files to run doctest in your python code files. seealso: https://docs.pytest.org/en/latest/example/pythoncollection.html#changing-naming-conventions and so on.
    • pytest does not run doctest by default and you have to give the option --doctest-modules when running pytest. seealso: https://docs.pytest.org/en/stable/doctest.html
    0 讨论(0)
  • 2021-01-01 15:25

    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.

    0 讨论(0)
  • 2021-01-01 15:36

    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.

    0 讨论(0)
  • 2021-01-01 15:37

    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.

    0 讨论(0)
提交回复
热议问题