Merge pull request #10609 from yusuke-kadowaki/default_policy_all
Change the default `tmp_path_retention_policy` to `all`
This commit is contained in:
commit
326ae0cd88
|
@ -1,2 +1 @@
|
||||||
Added :confval:`tmp_path_retention_count` and :confval:`tmp_path_retention_policy` configuration options to control how directories created by the :fixture:`tmp_path` fixture are kept.
|
Added :confval:`tmp_path_retention_count` and :confval:`tmp_path_retention_policy` configuration options to control how directories created by the :fixture:`tmp_path` fixture are kept.
|
||||||
The default behavior has changed to keep only directories for failed tests, equivalent to `tmp_path_retention_policy="failed"`.
|
|
||||||
|
|
|
@ -132,8 +132,7 @@ The default base temporary directory
|
||||||
Temporary directories are by default created as sub-directories of
|
Temporary directories are by default created as sub-directories of
|
||||||
the system temporary directory. The base name will be ``pytest-NUM`` where
|
the system temporary directory. The base name will be ``pytest-NUM`` where
|
||||||
``NUM`` will be incremented with each test run.
|
``NUM`` will be incremented with each test run.
|
||||||
By default, only the directories of failed tests will be kept.
|
By default, entries older than 3 temporary directories will be removed.
|
||||||
Also only the last 3 directries will remain at most.
|
|
||||||
This behavior can be configured with :confval:`tmp_path_retention_count` and
|
This behavior can be configured with :confval:`tmp_path_retention_count` and
|
||||||
:confval:`tmp_path_retention_policy`.
|
:confval:`tmp_path_retention_policy`.
|
||||||
|
|
||||||
|
|
|
@ -1754,7 +1754,7 @@ passed multiple times. The expected format is ``name=value``. For example::
|
||||||
[pytest]
|
[pytest]
|
||||||
tmp_path_retention_policy = "all"
|
tmp_path_retention_policy = "all"
|
||||||
|
|
||||||
Default: failed
|
Default: all
|
||||||
|
|
||||||
|
|
||||||
.. confval:: usefixtures
|
.. confval:: usefixtures
|
||||||
|
|
|
@ -239,7 +239,7 @@ def pytest_addoption(parser: Parser) -> None:
|
||||||
"tmp_path_retention_policy",
|
"tmp_path_retention_policy",
|
||||||
help="Controls which directories created by the `tmp_path` fixture are kept around, based on test outcome. "
|
help="Controls which directories created by the `tmp_path` fixture are kept around, based on test outcome. "
|
||||||
"(all/failed/none)",
|
"(all/failed/none)",
|
||||||
default="failed",
|
default="all",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -267,8 +267,8 @@ def tmp_path(
|
||||||
directory.
|
directory.
|
||||||
|
|
||||||
By default, a new base temporary directory is created each test session,
|
By default, a new base temporary directory is created each test session,
|
||||||
and only the base of failed session is kept. Also it only keeps the last 3 bases
|
and old bases are removed after 3 sessions, to aid in debugging.
|
||||||
at most. This can be configured with :confval:`tmp_path_retention_count` and
|
This behavior can be configured with :confval:`tmp_path_retention_count` and
|
||||||
:confval:`tmp_path_retention_policy`.
|
:confval:`tmp_path_retention_policy`.
|
||||||
If ``--basetemp`` is used then it is cleared each session. See :ref:`base
|
If ``--basetemp`` is used then it is cleared each session. See :ref:`base
|
||||||
temporary directory`.
|
temporary directory`.
|
||||||
|
|
|
@ -46,7 +46,7 @@ class FakeConfig:
|
||||||
if name == "tmp_path_retention_count":
|
if name == "tmp_path_retention_count":
|
||||||
return 3
|
return 3
|
||||||
elif name == "tmp_path_retention_policy":
|
elif name == "tmp_path_retention_policy":
|
||||||
return "failed"
|
return "all"
|
||||||
else:
|
else:
|
||||||
assert False
|
assert False
|
||||||
|
|
||||||
|
@ -101,6 +101,12 @@ class TestConfigTmpPath:
|
||||||
assert 0 == 1
|
assert 0 == 1
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
pytester.makepyprojecttoml(
|
||||||
|
"""
|
||||||
|
[tool.pytest.ini_options]
|
||||||
|
tmp_path_retention_policy = "failed"
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
pytester.inline_run(p)
|
pytester.inline_run(p)
|
||||||
root = pytester._test_tmproot
|
root = pytester._test_tmproot
|
||||||
|
@ -128,6 +134,12 @@ class TestConfigTmpPath:
|
||||||
assert 0 == 0
|
assert 0 == 0
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
pytester.makepyprojecttoml(
|
||||||
|
"""
|
||||||
|
[tool.pytest.ini_options]
|
||||||
|
tmp_path_retention_policy = "failed"
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
pytester.inline_run(p)
|
pytester.inline_run(p)
|
||||||
root = pytester._test_tmproot
|
root = pytester._test_tmproot
|
||||||
|
@ -155,6 +167,13 @@ class TestConfigTmpPath:
|
||||||
pass
|
pass
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
pytester.makepyprojecttoml(
|
||||||
|
"""
|
||||||
|
[tool.pytest.ini_options]
|
||||||
|
tmp_path_retention_policy = "failed"
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
pytester.inline_run(p)
|
pytester.inline_run(p)
|
||||||
|
|
||||||
# Check if the whole directory is removed
|
# Check if the whole directory is removed
|
||||||
|
@ -570,7 +589,7 @@ def test_tmp_path_factory_create_directory_with_safe_permissions(
|
||||||
"""Verify that pytest creates directories under /tmp with private permissions."""
|
"""Verify that pytest creates directories under /tmp with private permissions."""
|
||||||
# Use the test's tmp_path as the system temproot (/tmp).
|
# Use the test's tmp_path as the system temproot (/tmp).
|
||||||
monkeypatch.setenv("PYTEST_DEBUG_TEMPROOT", str(tmp_path))
|
monkeypatch.setenv("PYTEST_DEBUG_TEMPROOT", str(tmp_path))
|
||||||
tmp_factory = TempPathFactory(None, 3, "failed", lambda *args: None, _ispytest=True)
|
tmp_factory = TempPathFactory(None, 3, "all", lambda *args: None, _ispytest=True)
|
||||||
basetemp = tmp_factory.getbasetemp()
|
basetemp = tmp_factory.getbasetemp()
|
||||||
|
|
||||||
# No world-readable permissions.
|
# No world-readable permissions.
|
||||||
|
@ -590,14 +609,14 @@ def test_tmp_path_factory_fixes_up_world_readable_permissions(
|
||||||
"""
|
"""
|
||||||
# Use the test's tmp_path as the system temproot (/tmp).
|
# Use the test's tmp_path as the system temproot (/tmp).
|
||||||
monkeypatch.setenv("PYTEST_DEBUG_TEMPROOT", str(tmp_path))
|
monkeypatch.setenv("PYTEST_DEBUG_TEMPROOT", str(tmp_path))
|
||||||
tmp_factory = TempPathFactory(None, 3, "failed", lambda *args: None, _ispytest=True)
|
tmp_factory = TempPathFactory(None, 3, "all", lambda *args: None, _ispytest=True)
|
||||||
basetemp = tmp_factory.getbasetemp()
|
basetemp = tmp_factory.getbasetemp()
|
||||||
|
|
||||||
# Before - simulate bad perms.
|
# Before - simulate bad perms.
|
||||||
os.chmod(basetemp.parent, 0o777)
|
os.chmod(basetemp.parent, 0o777)
|
||||||
assert (basetemp.parent.stat().st_mode & 0o077) != 0
|
assert (basetemp.parent.stat().st_mode & 0o077) != 0
|
||||||
|
|
||||||
tmp_factory = TempPathFactory(None, 3, "failed", lambda *args: None, _ispytest=True)
|
tmp_factory = TempPathFactory(None, 3, "all", lambda *args: None, _ispytest=True)
|
||||||
basetemp = tmp_factory.getbasetemp()
|
basetemp = tmp_factory.getbasetemp()
|
||||||
|
|
||||||
# After - fixed.
|
# After - fixed.
|
||||||
|
|
Loading…
Reference in New Issue