| 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 |
|
| 12 |
from __future__ import annotations |
| 13 |
|
| 14 |
import os |
| 15 |
|
| 16 |
from _pytest.config import Config |
| 17 |
from _pytest.config import hookimpl |
| 18 |
from _pytest.terminal import TerminalProgressPlugin |
| 19 |
from _pytest.terminal import TerminalReporter |
| 20 |
|
| 21 |
|
| 22 |
@hookimpl(trylast=True) |
| 23 |
def pytest_configure(config: Config) -> None: |
| 24 |
reporter: TerminalReporter | None = config.pluginmanager.get_plugin( |
| 25 |
"terminalreporter" |
| 26 |
) |
| 27 |
|
| 28 |
if reporter is not None and reporter.isatty() and os.environ.get("TERM") != "dumb": |
| 29 |
plugin = TerminalProgressPlugin(reporter) |
| 30 |
config.pluginmanager.register(plugin, name="terminalprogress-plugin") |