Add integration tests for tmpdir
This commit is contained in:
parent
5ae5efc332
commit
a0b5dbc11b
|
@ -92,6 +92,74 @@ class TestConfigTmpPath:
|
|||
assert mytemp.exists()
|
||||
assert not mytemp.joinpath("hello").exists()
|
||||
|
||||
def test_policy_none_delete_all(self, pytester: Pytester) -> None:
|
||||
p = pytester.makepyfile(
|
||||
"""
|
||||
def test_1(tmp_path):
|
||||
assert 0 == 0
|
||||
"""
|
||||
)
|
||||
p_failed = pytester.makepyfile(
|
||||
"""
|
||||
def test_1(tmp_path):
|
||||
assert 0 == 1
|
||||
"""
|
||||
)
|
||||
pytester.makepyprojecttoml(
|
||||
"""
|
||||
[tool.pytest.ini_options]
|
||||
tmp_path_retention_policy = "none"
|
||||
"""
|
||||
)
|
||||
|
||||
pytester.inline_run(p)
|
||||
pytester.inline_run(p_failed)
|
||||
|
||||
root = pytester._test_tmproot
|
||||
for child in root.iterdir():
|
||||
base_dir = filter(lambda x: x.is_dir(), child.iterdir())
|
||||
# Check the base dir itself is gone without depending on test results
|
||||
assert len(list(base_dir)) == 0
|
||||
|
||||
@pytest.mark.parametrize("policy", ["failed", "all"])
|
||||
@pytest.mark.parametrize("count", [0, 1, 3])
|
||||
def test_retention_count(self, pytester: Pytester, policy, count) -> None:
|
||||
p = pytester.makepyfile(
|
||||
"""
|
||||
def test_1(tmp_path):
|
||||
assert 0 == 0
|
||||
"""
|
||||
)
|
||||
p_failed = pytester.makepyfile(
|
||||
"""
|
||||
def test_1(tmp_path):
|
||||
assert 0 == 1
|
||||
"""
|
||||
)
|
||||
|
||||
pytester.makepyprojecttoml(
|
||||
f"""
|
||||
[tool.pytest.ini_options]
|
||||
tmp_path_retention_policy = {policy}
|
||||
tmp_path_retention_count = {count}
|
||||
"""
|
||||
)
|
||||
|
||||
pytester.inline_run(p)
|
||||
pytester.inline_run(p_failed)
|
||||
pytester.inline_run(p)
|
||||
pytester.inline_run(p_failed)
|
||||
pytester.inline_run(p)
|
||||
pytester.inline_run(p_failed)
|
||||
pytester.inline_run(p)
|
||||
pytester.inline_run(p_failed)
|
||||
|
||||
root = pytester._test_tmproot
|
||||
for child in root.iterdir():
|
||||
base_dir = filter(lambda x: not x.is_symlink(), child.iterdir())
|
||||
# Check the base dir itself is gone
|
||||
assert len(list(base_dir)) == count
|
||||
|
||||
def test_policy_failed_removes_only_passed_dir(self, pytester: Pytester) -> None:
|
||||
p = pytester.makepyfile(
|
||||
"""
|
||||
|
@ -132,10 +200,7 @@ class TestConfigTmpPath:
|
|||
pytester.inline_run(p)
|
||||
root = pytester._test_tmproot
|
||||
for child in root.iterdir():
|
||||
# This symlink will be deleted by cleanup_numbered_dir **after**
|
||||
# the test finishes because it's triggered by atexit.
|
||||
# So it has to be ignored here.
|
||||
base_dir = filter(lambda x: not x.is_symlink(), child.iterdir())
|
||||
base_dir = filter(lambda x: x.is_dir(), child.iterdir())
|
||||
# Check the base dir itself is gone
|
||||
assert len(list(base_dir)) == 0
|
||||
|
||||
|
|
Loading…
Reference in New Issue