Update tests to check if the directory is removed or kept depending on the policy
This commit is contained in:
parent
1848da35a1
commit
e4cf09d8cb
|
@ -12,7 +12,6 @@ import attr
|
|||
import pytest
|
||||
from _pytest import pathlib
|
||||
from _pytest.config import Config
|
||||
from _pytest.config import ExitCode
|
||||
from _pytest.monkeypatch import MonkeyPatch
|
||||
from _pytest.pathlib import cleanup_numbered_dir
|
||||
from _pytest.pathlib import create_cleanup_lock
|
||||
|
@ -141,7 +140,9 @@ class TestConfigTmpPath:
|
|||
assert len(list(base_dir)) == 0
|
||||
|
||||
# issue #10502
|
||||
def test_delete_dir_when_skipped_from_fixture(self, pytester: Pytester) -> None:
|
||||
def test_policy_failed_removes_dir_when_skipped_from_fixture(
|
||||
self, pytester: Pytester
|
||||
) -> None:
|
||||
p = pytester.makepyfile(
|
||||
"""
|
||||
import pytest
|
||||
|
@ -154,9 +155,53 @@ class TestConfigTmpPath:
|
|||
pass
|
||||
"""
|
||||
)
|
||||
pytester.inline_run(p)
|
||||
|
||||
reprec = pytester.inline_run(p)
|
||||
assert reprec.ret == ExitCode.OK
|
||||
# Check if the whole directory is removed
|
||||
root = pytester._test_tmproot
|
||||
for child in root.iterdir():
|
||||
base_dir = list(
|
||||
filter(lambda x: x.is_dir() and not x.is_symlink(), child.iterdir())
|
||||
)
|
||||
assert len(base_dir) == 0
|
||||
|
||||
# issue #10502
|
||||
def test_policy_none_keeps_dir_when_skipped_from_fixture(
|
||||
self, pytester: Pytester
|
||||
) -> None:
|
||||
p = pytester.makepyfile(
|
||||
"""
|
||||
import pytest
|
||||
|
||||
@pytest.fixture
|
||||
def fixt(tmp_path):
|
||||
pytest.skip()
|
||||
|
||||
def test_fixt(fixt):
|
||||
pass
|
||||
"""
|
||||
)
|
||||
pytester.makepyprojecttoml(
|
||||
"""
|
||||
[tool.pytest.ini_options]
|
||||
tmp_path_retention_policy = "none"
|
||||
"""
|
||||
)
|
||||
pytester.inline_run(p)
|
||||
|
||||
# Check if the whole directory is kept
|
||||
root = pytester._test_tmproot
|
||||
for child in root.iterdir():
|
||||
base_dir = list(
|
||||
filter(lambda x: x.is_dir() and not x.is_symlink(), child.iterdir())
|
||||
)
|
||||
assert len(base_dir) == 1
|
||||
test_dir = list(
|
||||
filter(
|
||||
lambda x: x.is_dir() and not x.is_symlink(), base_dir[0].iterdir()
|
||||
)
|
||||
)
|
||||
assert len(test_dir) == 1
|
||||
|
||||
|
||||
testdata = [
|
||||
|
|
Loading…
Reference in New Issue