pytest-dev / pytest

The pytest framework makes it easy to write small tests, yet scales to support complex functional testing
https://pytest.org
MIT License
12.07k stars 2.67k forks source link

[FeatureRequest] Add --doctest-only to only collect doctests #4726

Open dhirschfeld opened 5 years ago

dhirschfeld commented 5 years ago

When using pytest on CI you often want to test doctests / unittests / intergration tests separately. To enable this usecase it would be good to have a --doctest-only flag to enable running only the doctests

dhirschfeld commented 5 years ago

xref: https://github.com/astropy/pytest-doctestplus/issues/14

RonnyPfannschmidt commented 5 years ago

based on context i am wondering if we should perhaps move towards making doctestplus the default doctest implementation

if memory serves me right, none of the core devs of pytest are deeply involved or happily using doctest

nicoddemus commented 5 years ago

if we should perhaps move towards making doctestplus the default doctest implementation

You mean integrating it into the core?

RonnyPfannschmidt commented 5 years ago

@nicoddemus no, taking it out ^^

dhirschfeld commented 5 years ago

I'm not fussed where it's implemented - I just opened an issue here since pytest already has some doctest functionality and this would be a great enhancement IMHO.

I'd be happy to install doctestplus if they implemented this - it would be it's killer feature for me!

RonnyPfannschmidt commented 5 years ago

i started a conversation with the relevant maintainers

bluetech commented 8 months ago

Because doctest is implemented as a logically independent plugin, there are two implementation strategies/perspectives for achieving this:

In doctest plugin

The doctest plugin adds a --doctest-only flag, implements a hook to filter out any non-doctest items.

Advantages:

Disadvantages:

In python plugin

The python plugin adds a flag to disable its own collection, e.g. --no-python-modules (name modeled after --doctest-modules, but other options can be --no-py-modules, --no-py-collect, ...)

Advantages/Disadvantages: basically the opposite of previous one.


While I think it made perfect sense for pytest-doctestplus to implement the first solution, I think for pytest the second solution is preferable.

bluetech commented 8 months ago

BTW, reading the pytest-doctestplus code, what they do is ignore all test_*.py files in --doctest-only mode. But test_*.py can also contain doctests, so IMO this is not very good. But currently they have no alternative if they want to avoid collecting the files/importing the modules (rather than collecting + discarding the items).