MCPcopy Create free account
hub / github.com/pytest-dev/pytest / cacheshow

Function cacheshow

src/_pytest/cacheprovider.py:541–580  ·  view source on GitHub ↗
(config: Config, session: Session)

Source from the content-addressed store, hash-verified

539
540
541def cacheshow(config: Config, session: Session) -> int:
542 from pprint import pformat
543
544 assert config.cache is not None
545
546 tw = TerminalWriter()
547 tw.line("cachedir: " + str(config.cache._cachedir))
548 if not config.cache._cachedir.is_dir():
549 tw.line("cache is empty")
550 return 0
551
552 glob = config.option.cacheshow[0]
553 if glob is None:
554 glob = "*"
555
556 dummy = object()
557 basedir = config.cache._cachedir
558 vdir = basedir / Cache._CACHE_PREFIX_VALUES
559 tw.sep("-", "cache values for %r" % glob)
560 for valpath in sorted(x for x in vdir.rglob(glob) if x.is_file()):
561 key = str(valpath.relative_to(vdir))
562 val = config.cache.get(key, dummy)
563 if val is dummy:
564 tw.line("%s contains unreadable content, will be ignored" % key)
565 else:
566 tw.line("%s contains:" % key)
567 for line in pformat(val).splitlines():
568 tw.line(" " + line)
569
570 ddir = basedir / Cache._CACHE_PREFIX_DIRS
571 if ddir.is_dir():
572 contents = sorted(ddir.rglob(glob))
573 tw.sep("-", "cache directories for %r" % glob)
574 for p in contents:
575 # if p.is_dir():
576 # print("%s/" % p.relative_to(basedir))
577 if p.is_file():
578 key = str(p.relative_to(basedir))
579 tw.line(f"{key} is a file of length {p.stat().st_size:d}")
580 return 0

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected