MCPcopy
hub / github.com/pytest-dev/pytest / test_gitignore

Function test_gitignore

testing/test_cacheprovider.py:1291–1318  ·  view source on GitHub ↗

Ensure we automatically create .gitignore file in the pytest_cache directory (#3286).

(
    pytester: Pytester,
    action: Action,
)

Source from the content-addressed store, hash-verified

1289
1290@pytest.mark.parametrize("action", list(Action))
1291def test_gitignore(
1292 pytester: Pytester,
1293 action: Action,
1294) -> None:
1295 """Ensure we automatically create .gitignore file in the pytest_cache directory (#3286)."""
1296 from _pytest.cacheprovider import Cache
1297
1298 config = pytester.parseconfig()
1299 cache = Cache.for_config(config, _ispytest=True)
1300 if action == Action.MKDIR:
1301 cache.mkdir("foo")
1302 elif action == Action.SET:
1303 cache.set("foo", "bar")
1304 else:
1305 assert_never(action)
1306 msg = "# Created by pytest automatically.\n*\n"
1307 gitignore_path = cache._cachedir.joinpath(".gitignore")
1308 assert gitignore_path.read_text(encoding="UTF-8") == msg
1309
1310 # Does not overwrite existing/custom one.
1311 gitignore_path.write_text("custom", encoding="utf-8")
1312 if action == Action.MKDIR:
1313 cache.mkdir("something")
1314 elif action == Action.SET:
1315 cache.set("something", "else")
1316 else:
1317 assert_never(action)
1318 assert gitignore_path.read_text(encoding="UTF-8") == "custom"
1319
1320
1321def test_preserve_keys_order(pytester: Pytester) -> None:

Callers

nothing calls this directly

Calls 7

assert_neverFunction · 0.90
for_configMethod · 0.80
setMethod · 0.80
read_textMethod · 0.80
write_textMethod · 0.80
parseconfigMethod · 0.45
mkdirMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…