The solution implemented in #3982 is not robust - in case test execution is interrupted while a cache element is being written, the .pytest_cache directory will exist and be non-empty, but will not contain .gitignore.
Because of this check .gitignore ends up never being created.