Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 15 additions & 4 deletions scpdt/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import numpy as np

from . import util
from .util import np_errstate, matplotlib_make_nongui

# Register the optionflag to skip whole blocks, i.e.
# sequences of Examples without an intervening text.
Expand Down Expand Up @@ -318,6 +319,7 @@ class DTRunner(doctest.DocTestRunner):
def __init__(self, checker=None, verbose=None, optionflags=None, config=None):
if config is None:
config = DTConfig()
self.config = config
if checker is None:
checker = DTChecker(config)
self.nameerror_after_exception = config.nameerror_after_exception
Expand Down Expand Up @@ -375,10 +377,19 @@ class DebugDTRunner(DTRunner):
Almost verbatim copy of `doctest.DebugRunner`.
"""
def run(self, test, compileflags=None, out=None, clear_globs=True):
r = super().run(test, compileflags, out, False)
if clear_globs:
test.globs.clear()
return r
"""
Run tests in context managers:
np_errstate: restores the numpy errstate and printoptions when done
user_context_manager: allows user to plug in their own context manager
matplotlib_make_nongui: temporarily make the matplotlib backend non-GUI
"""
with np_errstate():
with self.config.user_context_mgr(test):
with matplotlib_make_nongui():
r = super().run(test, compileflags=compileflags, out=out, clear_globs=False)
if clear_globs:
test.globs.clear()
return r

def report_unexpected_exception(self, out, test, example, exc_info):
super().report_unexpected_exception(out, test, example, exc_info)
Expand Down
32 changes: 20 additions & 12 deletions scpdt/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from _pytest.pathlib import import_path
from _pytest.outcomes import skip

from scpdt.impl import DTChecker, DTParser, DTFinder
from scpdt.impl import DTChecker, DTParser, DTFinder, DebugDTRunner
from scpdt.conftest import dt_config

copied_files = []
Expand All @@ -19,6 +19,7 @@ def pytest_configure(config):
Allow plugins and conftest files to perform initial configuration.
"""

doctest._get_runner = _get_runner
doctest._get_checker = _get_checker
doctest.DoctestModule = DTModule
doctest.DoctestTextfile = DTTextfile
Expand All @@ -39,7 +40,7 @@ def pytest_unconfigure(config):

def _get_checker():
"""
Override function to return an instance of DTChecker with default configurations
Override function to return an instance of DTChecker
"""
return DTChecker(config=dt_config)

Expand Down Expand Up @@ -99,16 +100,16 @@ def collect(self):
# We plugin scpdt's `DTFinder` that uses the `DTParser` which parses the doctest examples
# from the python module or file and filters out stopwords and pseudocode.
finder = DTFinder(config=dt_config)

# the rest remains unchanged
optionflags = doctest.get_optionflags(self)
runner = doctest._get_runner(

# We plugin scpdt's `DebugDTRunner`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# We plugin scpdt's `DebugDTRunner`
# We plug in scpdt's `DebugDTRunner`

runner = _get_runner(
verbose=False,
optionflags=optionflags,
checker=_get_checker(),
continue_on_failure=doctest._get_continue_on_failure(self.config),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we dropping continue_on_failure?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continue_on_failure is a pytest ini option. Figured it would be best to use DTConfig's nameerror_after_exception attribute instead since both do the same thing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#87 (comment) please make sure that this test passes with the plugin

checker=_get_checker()
)

# the rest remains unchanged
for test in finder.find(module, module.__name__):
if test.examples: # skip empty doctests
yield doctest.DoctestItem.from_parent(
Expand Down Expand Up @@ -138,11 +139,11 @@ def collect(self):
if dt_config.local_resources:
copy_local_files(dt_config.local_resources, os.getcwd())

runner = doctest._get_runner(
# We plugin scpdt's `DebugDTRunner`
runner = _get_runner(
verbose=False,
optionflags=optionflags,
checker=_get_checker(),
continue_on_failure=doctest._get_continue_on_failure(self.config)
checker=_get_checker()
)

# We plug in an instance of `DTParser` which parses the doctest examples from the text file and
Expand All @@ -159,6 +160,13 @@ def collect(self):

def _get_parser():
"""
Return instance of DTParser with default configuration
Return instance of DTParser
"""
return DTParser(config=dt_config)


def _get_runner(checker, verbose, optionflags):
"""
Override function to return instance of DebugDTRunner
"""
return DTParser(config=dt_config)
return DebugDTRunner(checker=checker, verbose=verbose, optionflags=optionflags, config=dt_config)