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
11.92k stars 2.66k forks source link

Add support for markers in doctests #5794

Open hmoravec opened 5 years ago

hmoravec commented 5 years ago

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

pandichef commented 4 years ago

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

mcepl commented 2 years ago

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.

nicoddemus commented 2 years ago

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.

mcepl commented 2 years ago

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!

nicoddemus commented 2 years ago

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.

fgmacedo commented 2 months ago

+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.