Skip to content

Commit

Permalink
Merge pull request #196 from effigies/enh/catch-skips
Browse files Browse the repository at this point in the history
ENH: Report doctests raising skip exceptions as skipped
  • Loading branch information
pllim authored Apr 1, 2023
2 parents a9c99ae + 6b909b7 commit 29cbdaa
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
0.12.2 (unreleased)
===================

- Report doctests raising skip exceptions as skipped. [#196]

0.12.1 (2022-09-26)
===================

Expand Down
14 changes: 12 additions & 2 deletions pytest_doctestplus/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import warnings
from pathlib import Path
from textwrap import indent
from unittest import SkipTest

import pytest
from _pytest.outcomes import OutcomeException # Private API, but been around since 3.7
from packaging.version import Version

from pytest_doctestplus.utils import ModuleChecker
Expand Down Expand Up @@ -258,7 +260,7 @@ def collect(self):

# uses internal doctest module parsing mechanism
finder = DocTestFinderPlus(doctest_ufunc=use_doctest_ufunc)
runner = doctest.DebugRunner(
runner = DebugRunnerPlus(
verbose=False, optionflags=options, checker=OutputChecker())

for test in finder.find(module):
Expand Down Expand Up @@ -320,7 +322,7 @@ def collect(self):

optionflags = get_optionflags(self) | FIX

runner = doctest.DebugRunner(
runner = DebugRunnerPlus(
verbose=False, optionflags=optionflags, checker=OutputChecker())

parser = DocTestParserPlus()
Expand Down Expand Up @@ -707,3 +709,11 @@ def test_filter(test):
tests = list(filter(test_filter, tests))

return tests


class DebugRunnerPlus(doctest.DebugRunner):
def report_unexpected_exception(self, out, test, example, exc_info):
cls, exception, traceback = exc_info
if isinstance(exception, (OutcomeException, SkipTest)):
raise exception
super().report_unexpected_exception(out, test, example, exc_info)
22 changes: 22 additions & 0 deletions tests/test_doctestplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,28 @@ def test_remote_data_ignore_warnings(testdir):
testdir.inline_run(p, '--doctest-plus', '--doctest-rst').assertoutcome(skipped=1)


def test_skiptest(testdir):
testdir.makeini(
"""
[pytest]
doctestplus = enabled
"""
)
p = testdir.makepyfile(
"""
class MyClass:
'''
>>> import pytest
>>> pytest.skip("I changed my mind")
>>> assert False, "This should not be reached"
'''
pass
"""
)
reprec = testdir.inline_run(p, "--doctest-plus")
reprec.assertoutcome(skipped=1, failed=0)


def test_ufunc(testdir):
pytest.importorskip('numpy')

Expand Down

0 comments on commit 29cbdaa

Please sign in to comment.