pytest icon indicating copy to clipboard operation
pytest copied to clipboard

Add support for markers in doctests

Open hmoravec opened this issue 6 years ago • 6 comments

It would be useful if also classes / methods / functions with doctests could be marked:

import pytest

@pytest.mark.custom_marker
def return_true():
    """Return True.

    >>> return_true()
    True
    """"
    return True

and then selected $ pytest -m custom_marker

hmoravec avatar Aug 27 '19 20:08 hmoravec

I second this. For example, I'd like to mark a doctest as @pytest.mark.slow. Is there any way to do this currently?

pandichef avatar Jul 18 '20 16:07 pandichef

I third this. I work for SUSE and our package build environments are isolated from network (the same goes from obvious reasons for all package distributions, Linux or not), so it is quite common to mark some tests as @pytest.mark.network and then skip those tests with %pytest -k not network.

Something like this would be very helpful:

    >>> Image('http://www.google.fr/images/srpr/logo3w.png')  # doctest: +pytest.mark.network

as a parallel of # doctest: +SKIP.

mcepl avatar Jan 15 '22 12:01 mcepl

I'm particularly 👎 on adding extra functionality to the doctests plugin that does not mirror a functionality in the standard library. I also don't find it appealing to use pytest functionality (pytest.mark) in production code.

nicoddemus avatar Jan 15 '22 14:01 nicoddemus

I'm particularly -1 on adding extra functionality to the doctests plugin that does not mirror a functionality in the standard library. I also don't find it appealing to use pytest functionality (pytest.mark) in production code.

I am glad you have your own idea how to do it. Please, do share!

mcepl avatar Jan 15 '22 14:01 mcepl

I am glad you have your own idea how to do it. Please, do share!

Oh but I don't, sorry if I wasn't clear.

nicoddemus avatar Jan 15 '22 14:01 nicoddemus

+1

I use doctests for all the examples in the documentation for python-statemachine. Some examples generate diagrams on disk. I want to skip those doctests and run them only before generating the documentation pages.

fgmacedo avatar Jul 09 '24 17:07 fgmacedo