Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
0.10.0 (unreleased)
===================

- Fixed a bug where the command-line option ``--remote-data=any`` (associated
with the ``pytest-remotedata`` plugin) would cause ``IGNORE_WARNINGS`` and
``SHOW_WARNINGS`` options to be ignored in module docstrings. [#152]

- Fix wrong behavior with ``IGNORE_WARNINGS`` and ``SHOW_WARNINGS`` that could
make a block to pass instead of being skipped. [#148]

Expand Down
62 changes: 30 additions & 32 deletions pytest_doctestplus/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,38 +219,36 @@ def collect(self):

for test in finder.find(module):
if test.examples: # skip empty doctests
if config.getoption('remote_data', 'none') != 'any':

ignore_warnings_context_needed = False
show_warnings_context_needed = False

for example in test.examples:

# If warnings are to be ignored we need to catch them by
# wrapping the source in a context manager.
if example.options.get(IGNORE_WARNINGS, False):
example.source = ("with _doctestplus_ignore_all_warnings():\n"
+ indent(example.source, ' '))
ignore_warnings_context_needed = True

# Same for SHOW_WARNINGS
if example.options.get(SHOW_WARNINGS, False):
example.source = ("with _doctestplus_show_all_warnings():\n"
+ indent(example.source, ' '))
show_warnings_context_needed = True

if example.options.get(REMOTE_DATA):
example.options[doctest.SKIP] = True

# We insert the definition of the context manager to ignore
# warnings at the start of the file if needed.
if ignore_warnings_context_needed:
test.examples.insert(0, doctest.Example(
source=IGNORE_WARNINGS_CONTEXT, want=''))

if show_warnings_context_needed:
test.examples.insert(0, doctest.Example(
source=SHOW_WARNINGS_CONTEXT, want=''))
ignore_warnings_context_needed = False
show_warnings_context_needed = False

for example in test.examples:
if (config.getoption('remote_data', 'none') != 'any'
and example.options.get(REMOTE_DATA)):
example.options[doctest.SKIP] = True

# If warnings are to be ignored we need to catch them by
# wrapping the source in a context manager.
elif example.options.get(IGNORE_WARNINGS, False):
example.source = ("with _doctestplus_ignore_all_warnings():\n"
+ indent(example.source, ' '))
ignore_warnings_context_needed = True

# Same for SHOW_WARNINGS
elif example.options.get(SHOW_WARNINGS, False):
example.source = ("with _doctestplus_show_all_warnings():\n"
+ indent(example.source, ' '))
show_warnings_context_needed = True

# We insert the definition of the context manager to ignore
# warnings at the start of the file if needed.
if ignore_warnings_context_needed:
test.examples.insert(0, doctest.Example(
source=IGNORE_WARNINGS_CONTEXT, want=''))

if show_warnings_context_needed:
test.examples.insert(0, doctest.Example(
source=SHOW_WARNINGS_CONTEXT, want=''))

try:
yield doctest_plugin.DoctestItem.from_parent(
Expand Down