Ensure we automatically create .gitignore file in the pytest_cache directory (#3286).
(
pytester: Pytester,
action: Action,
)
| 1289 | |
| 1290 | @pytest.mark.parametrize("action", list(Action)) |
| 1291 | def 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 | |
| 1321 | def test_preserve_keys_order(pytester: Pytester) -> None: |
nothing calls this directly
no test coverage detected
searching dependent graphs…