Merge pull request #5676 from pfmoore/keep_tmpdir

Add a command line option to keep temporary directories when testing
This commit is contained in:
Paul Moore 2018-07-30 22:36:48 +01:00 committed by GitHub
commit db127330d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 2 deletions

View File

@ -14,6 +14,13 @@ from tests.lib.scripttest import PipTestEnvironment
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
@ -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
@ -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)