Skip to content

Commit

Permalink
Merge pull request #5676 from pfmoore/keep_tmpdir
Browse files Browse the repository at this point in the history
Add a command line option to keep temporary directories when testing
  • Loading branch information
pfmoore authored Jul 30, 2018
2 parents b2b6295 + 3a485da commit db12733
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
from tests.lib.venv import VirtualEnvironment


def pytest_addoption(parser):
parser.addoption(
"--keep-tmpdir", action="store_true",
default=False, help="keep temporary test directories"
)


def pytest_collection_modifyitems(items):
for item in items:
if not hasattr(item, 'module'): # e.g.: DoctestTextfile
Expand Down Expand Up @@ -50,7 +57,7 @@ def pytest_collection_modifyitems(items):


@pytest.yield_fixture
def tmpdir(tmpdir):
def tmpdir(request, tmpdir):
"""
Return a temporary directory path object which is unique to each test
function invocation, created as a sub directory of the base temporary
Expand All @@ -65,7 +72,8 @@ def tmpdir(tmpdir):
# Clear out the temporary directory after the test has finished using it.
# This should prevent us from needing a multiple gigabyte temporary
# directory while running the tests.
tmpdir.remove(ignore_errors=True)
if not request.config.getoption("--keep-tmpdir"):
tmpdir.remove(ignore_errors=True)


@pytest.fixture(autouse=True)
Expand Down

0 comments on commit db12733

Please sign in to comment.