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

Function test_gitignore

testing/test_cacheprovider.py:1291–1318  ·  testing/test_cacheprovider.py::test_gitignore

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(class="st">"action", list(Action))
1291def test_gitignore(
1292 pytester: Pytester,
1293 action: Action,
1294) -> None:
1295 class="st">""class="st">"Ensure we automatically create .gitignore file in the pytest_cache directory (class="cm">#3286)."class="st">""
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(class="st">"foo")
1302 elif action == Action.SET:
1303 cache.set(class="st">"foo", class="st">"bar")
1304 else:
1305 assert_never(action)
1306 msg = class="st">"class="cm"># Created by pytest automatically.\n*\n"
1307 gitignore_path = cache._cachedir.joinpath(class="st">".gitignore")
1308 assert gitignore_path.read_text(encoding=class="st">"UTF-8") == msg
1309
1310 class="cm"># Does not overwrite existing/custom one.
1311 gitignore_path.write_text(class="st">"custom", encoding=class="st">"utf-8")
1312 if action == Action.MKDIR:
1313 cache.mkdir(class="st">"something")
1314 elif action == Action.SET:
1315 cache.set(class="st">"something", class="st">"else")
1316 else:
1317 assert_never(action)
1318 assert gitignore_path.read_text(encoding=class="st">"UTF-8") == class="st">"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