-
Notifications
You must be signed in to change notification settings - Fork 39
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
Jail doctestplus outputs in tmpdir #98
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,23 @@ def __exit__(self, *args, **kwargs): | |
""".lstrip() | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def _docdir(request): | ||
"""Run doctests in isolated tmpdir so outputs do not end up in repo""" | ||
# Trigger ONLY for doctestplus | ||
doctest_plugin = request.config.pluginmanager.getplugin("pytest_doctestplus") | ||
if isinstance(request.node, doctest_plugin.DocTestTextfilePlus): | ||
# Don't apply this fixture to io.rst. It reads files and doesn't write | ||
if "io.rst" not in request.node.name: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only based on the narrative, I don't get why would it hurt to still apply when it reads files but not writes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, this is specific to the astropy core library. The problem with that doctest is that it looks for an input file in the working directory. If one makes the working dir a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm looks like importlib.resources is only available since Python 3.7. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is available as an external package for python 3.6 and earlier. |
||
tmpdir = request.getfixturevalue('tmpdir') | ||
with tmpdir.as_cwd(): | ||
yield | ||
else: | ||
yield | ||
else: | ||
yield | ||
|
||
|
||
# these pytest hooks allow us to mark tests and run the marked tests with | ||
# specific command line options. | ||
def pytest_addoption(parser): | ||
|
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.
Not sure how to access the class name when this fixture lives in the plugin itself and not over at core lib.