Skip to content

'--cache-clear' option to regenerate the cache folder is missing some files #6290

Closed
@luizyao

Description

@luizyao

Description

Before I used --cache-clear option, my cache folder looked like this:

.pytest_cache/
├── .gitignore
├── CACHEDIR.TAG
├── README.md
└── v
    └── cache
        ├── nodeids
        └── stepwise

2 directories, 5 files

then I add --cache-clear option to re-execute, my cache folder looks like this:

.pytest_cache/
└── v
    └── cache
        ├── nodeids
        └── stepwise

2 directories, 2 files

Three files are missing: .gitignore CACHEDIR.TAG and README.md.

This lets me commit files that I don't want to upload while using git commit.

Question

I check the src/_pytest/cacheprovider.py file in source codes.

    @classmethod
    def for_config(cls, config):
        cachedir = cls.cache_dir_from_config(config)
        if config.getoption("cacheclear") and cachedir.exists():
            rm_rf(cachedir)
            cachedir.mkdir()
        return cls(cachedir, config)

I think this issue is caused by this line: cachedir.mkdir(), it will make cache_dir_exists_already True, so that _ensure_supporting_files function not to be called.

       try:
            if path.parent.is_dir():
                cache_dir_exists_already = True
            else:
                cache_dir_exists_already = self._cachedir.exists()
                path.parent.mkdir(exist_ok=True, parents=True)
        except (IOError, OSError):
            self.warn("could not create cache path {path}", path=path)
            return
        if not cache_dir_exists_already:
            self._ensure_supporting_files()

I don't understand why this operation was added. Is there anything else I don't know about it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueeasy issue that is friendly to new contributorplugin: cacherelated to the cache builtin pluginstatus: help wanteddevelopers would like help from experts on this topic

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions