terminalprogress.py 1.1 KB

123456789101112131415161718192021222324252627282930
  1. # A plugin to register the TerminalProgressPlugin plugin.
  2. #
  3. # This plugin is not loaded by default due to compatibility issues (#13896),
  4. # but can be enabled in one of these ways:
  5. # - The terminal plugin enables it in a few cases where it's safe, and not
  6. # blocked by the user (using e.g. `-p no:terminalprogress`).
  7. # - The user explicitly requests it, e.g. using `-p terminalprogress`.
  8. #
  9. # In a few years, if it's safe, we can consider enabling it by default. Then,
  10. # this file will become unnecessary and can be inlined into terminal.py.
  11. from __future__ import annotations
  12. import os
  13. from _pytest.config import Config
  14. from _pytest.config import hookimpl
  15. from _pytest.terminal import TerminalProgressPlugin
  16. from _pytest.terminal import TerminalReporter
  17. @hookimpl(trylast=True)
  18. def pytest_configure(config: Config) -> None:
  19. reporter: TerminalReporter | None = config.pluginmanager.get_plugin(
  20. "terminalreporter"
  21. )
  22. if reporter is not None and reporter.isatty() and os.environ.get("TERM") != "dumb":
  23. plugin = TerminalProgressPlugin(reporter)
  24. config.pluginmanager.register(plugin, name="terminalprogress-plugin")