-
-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Run tests in context managers #87
Conversation
Bug if out is None:
encoding = save_stdout.encoding
if encoding is None or encoding.lower() == 'utf-8':
out = save_stdout.write
else:
# Use backslashreplace error handling on write
def out(s):
s = str(s.encode(encoding, 'backslashreplace'), encoding)
save_stdout.write(s) From the code implementation here in the DTRunner def _report_item_name(self, out, item_name, new_line=False):
if item_name is not None:
out("\n " + item_name + "\n " + "-"*len(item_name))
if new_line:
out("\n")
|
What does DebugDTRunner have to do with any of this? Its only job is to stop after the first failure, so it' |
I opted to override its |
I can override the |
Ah OK, this might make sense if pytest runs doctests one by one needs to override the reporting. Let's come back to this after the weekend. EDIT: For usual doctests, |
It would probably be a good idea to make |
@ev-br does Edit: it actually does. So I will use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Several comments in-line, none of them blocking. Please address those which are easy, and add TODO comments for the rest.
The pytest code style is a little baroque with local imports and local classes, can move them to the module level in a clean-up. We should at some point also look into minimizing copy-paste from pytest, this is also for some other day.
There are likely several bugs lurking, these should be smoked out with dogfooding on scipy documentation, which should be the next step IMO.
scpdt/impl.py
Outdated
@@ -375,7 +376,7 @@ 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) | |||
r = super().run(test, compileflags=compileflags, out=out, clear_globs=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kwargs do make it read much better, thank you!
Now that I look at this, why does it drop clear_globs
argument? This is pre-existing of course, can we pass it here nonetheless? At this point, probably best to just add an TODO
comment and move on though.
scpdt/plugin.py
Outdated
optionflags = doctest.get_optionflags(self) | ||
runner = doctest._get_runner( | ||
|
||
# We plugin scpdt's `DebugDTRunner` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# We plugin scpdt's `DebugDTRunner` | |
# We plug in scpdt's `DebugDTRunner` |
verbose=False, | ||
optionflags=optionflags, | ||
checker=_get_checker(), | ||
continue_on_failure=doctest._get_continue_on_failure(self.config), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
|
||
|
||
def _get_runner(checker, verbose, optionflags): | ||
import doctest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: there is probably no reason to hide imports; move it to the module level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's because of this error:
AttributeError: module '_pytest.doctest' has no attribute 'UnexpectedException'
scpdt/plugin.py
Outdated
|
||
""" | ||
Almost verbatim copy of `_pytest.doctest.PytestDoctestRunner`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please detail the differences.
scpdt/plugin.py
Outdated
execution of the particular doctest | ||
""" | ||
self.continue_on_failure = continue_on_failure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
config
argument is ignored, what is self.config
below in self.config.user_context_mgr
. This ties up to a question of where the global DTConfig lives.
Not sure actually. I don't know what EDIT: the relevant test is |
@ev-br
AttributeError: module '_pytest.doctest' has no attribute 'UnexpectedException'
|
LGTM, thank you Sheila! Let's not worry about cleanups at this stage, I'll do a holistic review later anyway. |
DebugDTRunner
run
function to ensure tests are run in context managersCloses #82