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

Class TerminalReporter

src/_pytest/terminal.py:379–1504  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

377
378@final
379class TerminalReporter:
380 def __init__(self, config: Config, file: TextIO | None = None) -> None:
381 import _pytest.config
382
383 self.config = config
384 self._numcollected = 0
385 self._session: Session | None = None
386 self._showfspath: bool | None = None
387
388 self.stats: dict[str, list[Any]] = {}
389 self._main_color: str | None = None
390 self._known_types: list[str] | None = None
391 self.startpath = config.invocation_params.dir
392 if file is None:
393 file = sys.stdout
394 self._tw = _pytest.config.create_terminal_writer(config, file)
395 self._screen_width = self._tw.fullwidth
396 self.currentfspath: None | Path | str | int = None
397 self.reportchars = getreportopt(config)
398 self.foldskipped = config.option.fold_skipped
399 self.hasmarkup = self._tw.hasmarkup
400 # isatty should be a method but was wrongly implemented as a boolean.
401 # We use CallableBool here to support both.
402 self.isatty = compat.CallableBool(file.isatty())
403 self._progress_nodeids_reported: set[str] = set()
404 self._timing_nodeids_reported: set[str] = set()
405 self._show_progress_info = self._determine_show_progress_info()
406 self._collect_report_last_write = timing.Instant()
407 self._already_displayed_warnings: int | None = None
408 self._keyboardinterrupt_memo: ExceptionRepr | None = None
409
410 def _determine_show_progress_info(
411 self,
412 ) -> Literal["progress", "count", "times", False]:
413 """Return whether we should display progress information based on the current config."""
414 # do not show progress if we are not capturing output (#3038) unless explicitly
415 # overridden by progress-even-when-capture-no
416 if (
417 self.config.getoption("capture", "no") == "no"
418 and self.config.getini("console_output_style")
419 != "progress-even-when-capture-no"
420 ):
421 return False
422 # do not show progress if we are showing fixture setup/teardown
423 if self.config.getoption("setupshow", False):
424 return False
425 cfg: str = self.config.getini("console_output_style")
426 if cfg in {"progress", "progress-even-when-capture-no"}:
427 return "progress"
428 elif cfg == "count":
429 return "count"
430 elif cfg == "times":
431 return "times"
432 else:
433 return False
434
435 @property
436 def verbosity(self) -> int:

Callers 7

test_internalerrorMethod · 0.90
test_writelineMethod · 0.90
test_rewriteMethod · 0.90
test_isattyMethod · 0.90
trFunction · 0.90
pytest_configureFunction · 0.85

Calls

no outgoing calls

Tested by 6

test_internalerrorMethod · 0.72
test_writelineMethod · 0.72
test_rewriteMethod · 0.72
test_isattyMethod · 0.72
trFunction · 0.72