Skip to content

Commit

Permalink
Jail doctestplus outputs in tmpdir.
Browse files Browse the repository at this point in the history
Co-authored-by: James Davies <[email protected]>
  • Loading branch information
pllim and jdavies-st committed Mar 13, 2020
1 parent d3d2207 commit c632a15
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pytest_doctestplus/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("doctestplus")
if isinstance(request.node, doctest_plugin._doctest_textfile_item_cls):
# Don't apply this fixture to io.rst. It reads files and doesn't write
if "io.rst" not in request.node.name:
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):
Expand Down

0 comments on commit c632a15

Please sign in to comment.