Created
May 7, 2021 09:19
-
-
Save clbarnes/d70874628a9c24df8825c07930b4760b to your computer and use it in GitHub Desktop.
Temporary directories for in-package doctests managed by pytest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Configuration for in-package doctests. | |
Should be importable (but not useful) | |
without development dependencies. | |
Where these files up and when they are deleted is documented | |
`here <https://pytest.org/en/stable/tmpdir.html#the-default-base-temporary-directory>`_. | |
""" | |
from pathlib import Path | |
try: | |
import pytest | |
decorator = pytest.fixture(autouse=True) | |
except ImportError: | |
def decorator(fn): | |
return fn | |
@decorator | |
def add_tmp_dir(doctest_namespace, tmpdir): | |
"""Give all doctests access to a ``tmp_dir`` variable. | |
``tmp_dir`` is a ``pathlib.Path`` to a real directory | |
in pytest's tmp directory which is automatically cleaned up | |
in later invocations of ``pytest``. | |
""" | |
doctest_namespace["tmp_dir"] = Path(tmpdir) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment