diff --git a/AUTHORS b/AUTHORS index 85fe6aff0..d6f6ce828 100644 --- a/AUTHORS +++ b/AUTHORS @@ -222,6 +222,7 @@ Steffen Allner Stephan Obermann Sven-Hendrik Haase Tadek Teleżyński +Takafumi Arakaki Tarcisio Fischer Tareq Alayan Ted Xiao diff --git a/changelog/4911.feature.rst b/changelog/4911.feature.rst new file mode 100644 index 000000000..5106e6fb9 --- /dev/null +++ b/changelog/4911.feature.rst @@ -0,0 +1 @@ +Doctest can be now skipped dynamically with `pytest.skip`. diff --git a/src/_pytest/outcomes.py b/src/_pytest/outcomes.py index 14c6e9ab6..b08dbc7b3 100644 --- a/src/_pytest/outcomes.py +++ b/src/_pytest/outcomes.py @@ -80,7 +80,8 @@ def skip(msg="", **kwargs): Skip an executing test with the given message. This function should be called only during testing (setup, call or teardown) or - during collection by using the ``allow_module_level`` flag. + during collection by using the ``allow_module_level`` flag. This function can + be called in doctest as well. :kwarg bool allow_module_level: allows this function to be called at module level, skipping the rest of the module. Default to False. @@ -89,6 +90,9 @@ def skip(msg="", **kwargs): It is better to use the :ref:`pytest.mark.skipif ref` marker when possible to declare a test to be skipped under certain conditions like mismatching platforms or dependencies. + Similarly, use ``# doctest: +SKIP`` directive (see `doctest.SKIP + `_) + to skip a doctest statically. """ __tracebackhide__ = True allow_module_level = kwargs.pop("allow_module_level", False)