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

Function _showfixtures_main

src/_pytest/fixtures.py:2275–2329  ·  view source on GitHub ↗
(config: Config, session: Session)

Source from the content-addressed store, hash-verified

2273
2274
2275def _showfixtures_main(config: Config, session: Session) -> None:
2276 import _pytest.config
2277
2278 session.perform_collect()
2279 invocation_dir = config.invocation_params.dir
2280 tw = _pytest.config.create_terminal_writer(config)
2281 verbose = config.get_verbosity()
2282
2283 fm = session._fixturemanager
2284
2285 available = []
2286 seen: set[tuple[str, str]] = set()
2287
2288 for argname, fixturedefs in fm._arg2fixturedefs.items():
2289 assert fixturedefs is not None
2290 if not fixturedefs:
2291 continue
2292 for fixturedef in fixturedefs:
2293 loc = getlocation(fixturedef.func, invocation_dir)
2294 if (fixturedef.argname, loc) in seen:
2295 continue
2296 seen.add((fixturedef.argname, loc))
2297 available.append(
2298 (
2299 len(fixturedef.baseid),
2300 fixturedef.func.__module__,
2301 _pretty_fixture_path(invocation_dir, fixturedef.func),
2302 fixturedef.argname,
2303 fixturedef,
2304 )
2305 )
2306
2307 available.sort()
2308 currentmodule = None
2309 for baseid, module, prettypath, argname, fixturedef in available:
2310 if currentmodule != module:
2311 if not module.startswith("_pytest."):
2312 tw.line()
2313 tw.sep("-", f"fixtures defined from {module}")
2314 currentmodule = module
2315 if verbose <= 0 and argname.startswith("_"):
2316 continue
2317 tw.write(f"{argname}", green=True)
2318 if fixturedef.scope != "function":
2319 tw.write(f" [{fixturedef.scope} scope]", cyan=True)
2320 tw.write(f" -- {prettypath}", yellow=True)
2321 tw.write("\n")
2322 doc = inspect.getdoc(fixturedef.func)
2323 if doc:
2324 write_docstring(
2325 tw, doc.split("\n\n", maxsplit=1)[0] if verbose <= 0 else doc
2326 )
2327 else:
2328 tw.line(" no docstring available", red=True)
2329 tw.line()
2330
2331
2332def write_docstring(tw: TerminalWriter, doc: str, indent: str = " ") -> None:

Callers

nothing calls this directly

Calls 9

getlocationFunction · 0.90
_pretty_fixture_pathFunction · 0.85
write_docstringFunction · 0.85
perform_collectMethod · 0.80
appendMethod · 0.80
get_verbosityMethod · 0.45
lineMethod · 0.45
sepMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected