Skip to content

Commit

Permalink
Additional check for bad decorators
Browse files Browse the repository at this point in the history
  • Loading branch information
Erotemic committed Jan 13, 2023
1 parent 40fe8c5 commit f212145
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/xdoctest/directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ def _is_requires_satisfied(arg, argv=None, environ=None):
Example:
>>> from xdoctest.directive import * # NOQA
>>> from xdoctest.directive import _is_requires_satisfied
>>> _is_requires_satisfied('PY2', argv=[])
>>> _is_requires_satisfied('PY3', argv=[])
>>> _is_requires_satisfied('cpython', argv=[])
Expand Down
45 changes: 44 additions & 1 deletion tests/test_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def test(self, s):
assert 'running 0 test' in text


def test_correct_skipping_on_decorators():
def test_correct_skipping_on_decorators1():
"""
This is a weird case similar to the torch dispatch doctest
Expand Down Expand Up @@ -180,3 +180,46 @@ def dispatch(*types, **kwargs):
runner.doctest_module(modpath, 'all', argv=[''], config=config)
print(cap.text)
assert '1 skipped' in cap.text


def test_correct_skipping_on_decorators_simple():
"""
minimal test for decorator skips
"""

import xdoctest
from xdoctest import runner
from os.path import join

source = utils.codeblock(
'''
def _my_decorator():
"""
Example:
>>> # xdoctest: +SKIP
>>> @_my_decorator()
... def my_func(x):
... ...
>>> f(3)
"""
return
''')

config = {
'style': 'google',
}
temp = utils.TempDir()
dpath = temp.ensure()
with temp as temp:
modpath = join(dpath, 'test_example_run.py')

with open(modpath, 'w') as file:
file.write(source)

examples = list(xdoctest.core.parse_doctestables(modpath, style='google', analysis='static'))
print(f'examples={examples}')

with utils.CaptureStdout() as cap:
runner.doctest_module(modpath, 'all', argv=[''], config=config)
print(cap.text)
assert '1 skipped' in cap.text

0 comments on commit f212145

Please sign in to comment.