Skip to content

Commit e06c337

Browse files
committed
Add test for Cache.mkdir
1 parent a02cc0a commit e06c337

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

testing/test_cacheprovider.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from enum import auto
2+
from enum import Enum
13
import os
24
from pathlib import Path
35
import shutil
@@ -7,6 +9,7 @@
79
from typing import Sequence
810
from typing import Tuple
911

12+
from _pytest.compat import assert_never
1013
from _pytest.config import ExitCode
1114
from _pytest.monkeypatch import MonkeyPatch
1215
from _pytest.pytester import Pytester
@@ -1260,20 +1263,41 @@ def test_readme_failed(self, pytester: Pytester) -> None:
12601263
assert self.check_readme(pytester) is True
12611264

12621265

1263-
def test_gitignore(pytester: Pytester) -> None:
1266+
class Action(Enum):
1267+
"""Action to perform on the cache directory."""
1268+
1269+
MKDIR = auto()
1270+
SET = auto()
1271+
1272+
1273+
@pytest.mark.parametrize("action", list(Action))
1274+
def test_gitignore(
1275+
pytester: Pytester,
1276+
action: Action,
1277+
) -> None:
12641278
"""Ensure we automatically create .gitignore file in the pytest_cache directory (#3286)."""
12651279
from _pytest.cacheprovider import Cache
12661280

12671281
config = pytester.parseconfig()
12681282
cache = Cache.for_config(config, _ispytest=True)
1269-
cache.set("foo", "bar")
1283+
if action == Action.MKDIR:
1284+
cache.mkdir("foo")
1285+
elif action == Action.SET:
1286+
cache.set("foo", "bar")
1287+
else:
1288+
assert_never(action)
12701289
msg = "# Created by pytest automatically.\n*\n"
12711290
gitignore_path = cache._cachedir.joinpath(".gitignore")
12721291
assert gitignore_path.read_text(encoding="UTF-8") == msg
12731292

12741293
# Does not overwrite existing/custom one.
12751294
gitignore_path.write_text("custom", encoding="utf-8")
1276-
cache.set("something", "else")
1295+
if action == Action.MKDIR:
1296+
cache.mkdir("something")
1297+
elif action == Action.SET:
1298+
cache.set("something", "else")
1299+
else:
1300+
assert_never(action)
12771301
assert gitignore_path.read_text(encoding="UTF-8") == "custom"
12781302

12791303

0 commit comments

Comments
 (0)