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

Function cacheshow

src/_pytest/cacheprovider.py:591–640  ·  view source on GitHub ↗

Display cache contents when --cache-show is used. Shows cached values and directories matching the specified glob pattern (default: '*'). Displays cache location, cached test results, and any cached directories created by plugins. :param config: pytest configuration object. :pa

(config: Config, session: Session)

Source from the content-addressed store, hash-verified

589
590
591def cacheshow(config: Config, session: Session) -> int:
592 """Display cache contents when --cache-show is used.
593
594 Shows cached values and directories matching the specified glob pattern
595 (default: '*'). Displays cache location, cached test results, and
596 any cached directories created by plugins.
597
598 :param config: pytest configuration object.
599 :param session: pytest session object.
600 :returns: Exit code (0 for success).
601 """
602 from pprint import pformat
603
604 assert config.cache is not None
605
606 tw = TerminalWriter()
607 tw.line("cachedir: " + str(config.cache._cachedir))
608 if not config.cache._cachedir.is_dir():
609 tw.line("cache is empty")
610 return 0
611
612 glob = config.option.cacheshow[0]
613 if glob is None:
614 glob = "*"
615
616 dummy = object()
617 basedir = config.cache._cachedir
618 vdir = basedir / Cache._CACHE_PREFIX_VALUES
619 tw.sep("-", f"cache values for {glob!r}")
620 for valpath in sorted(x for x in vdir.rglob(glob) if x.is_file()):
621 key = str(valpath.relative_to(vdir))
622 val = config.cache.get(key, dummy)
623 if val is dummy:
624 tw.line(f"{key} contains unreadable content, will be ignored")
625 else:
626 tw.line(f"{key} contains:")
627 for line in pformat(val).splitlines():
628 tw.line(" " + line)
629
630 ddir = basedir / Cache._CACHE_PREFIX_DIRS
631 if ddir.is_dir():
632 contents = sorted(ddir.rglob(glob))
633 tw.sep("-", f"cache directories for {glob!r}")
634 for p in contents:
635 # if p.is_dir():
636 # print("%s/" % p.relative_to(basedir))
637 if p.is_file():
638 key = str(p.relative_to(basedir))
639 tw.line(f"{key} is a file of length {p.stat().st_size}")
640 return 0

Callers

nothing calls this directly

Calls 5

lineMethod · 0.95
sepMethod · 0.95
TerminalWriterClass · 0.90
statMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…