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