Skip to content

Commit

Permalink
ENH: adding doctest-remote-data-all directive
Browse files Browse the repository at this point in the history
  • Loading branch information
bsipocz committed Jan 24, 2025
1 parent d620c96 commit 4e647a2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
20 changes: 16 additions & 4 deletions pytest_doctestplus/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,9 @@ class DocTestParserPlus(doctest.DocTestParser):
- ``.. doctest-remote-data::``: Skip the next doctest chunk if
--remote-data is not passed.
- ``.. doctest-remote-data-all::``: Skip all subsequent doctest
chunks if --remote-data is not passed.
"""

def parse(self, s, name=None):
Expand Down Expand Up @@ -429,15 +432,24 @@ def parse(self, s, name=None):
required_all = []
skip_next = False
lines = entry.strip().splitlines()

requires_all_match = [re.match(
fr'{comment_char}\s+doctest-requires-all\s*::\s+(.*)', x) for x in lines]
if any(requires_all_match):
required_all = [re.split(r'\s*[,\s]\s*', match.group(1)) for match in requires_all_match if match][0]

required_all = [re.split(r'\s*[,\s]\s*', match.group(1))
for match in requires_all_match if match][0]
required_modules_all = DocTestFinderPlus.check_required_modules(required_all)
if not required_modules_all:
skip_all = True
continue

if config.getoption('remote_data', 'none') != 'any':
if any(re.match(fr'{comment_char} doctest-remote-data-all::', x.strip())
for x in lines):
skip_all = True
continue

if any(re.match(
f'{comment_char} doctest-skip-all', x.strip()) for x in lines) or not required_modules_all:
if any(re.match(f'{comment_char} doctest-skip-all', x.strip()) for x in lines):
skip_all = True
continue

Expand Down
1 change: 1 addition & 0 deletions pytest_doctestplus/sphinx/doctestplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def setup(app):
app.add_directive('doctest-skip-all', DoctestSkipDirective)
app.add_directive('doctest', DoctestSkipDirective, override=True)
app.add_directive('doctest-remote-data', DoctestSkipDirective)
app.add_directive('doctest-remote-data-all', DoctestSkipDirective)
# Code blocks that use this directive will not appear in the generated
# documentation. This is intended to hide boilerplate code that is only
# useful for testing documentation using doctest, but does not actually
Expand Down

0 comments on commit 4e647a2

Please sign in to comment.