Skip to content

Commit db12733

Browse files
authored
Merge pull request #5676 from pfmoore/keep_tmpdir
Add a command line option to keep temporary directories when testing
2 parents b2b6295 + 3a485da commit db12733

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

tests/conftest.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
from tests.lib.venv import VirtualEnvironment
1515

1616

17+
def pytest_addoption(parser):
18+
parser.addoption(
19+
"--keep-tmpdir", action="store_true",
20+
default=False, help="keep temporary test directories"
21+
)
22+
23+
1724
def pytest_collection_modifyitems(items):
1825
for item in items:
1926
if not hasattr(item, 'module'): # e.g.: DoctestTextfile
@@ -50,7 +57,7 @@ def pytest_collection_modifyitems(items):
5057

5158

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

7078

7179
@pytest.fixture(autouse=True)

0 commit comments

Comments
 (0)