Merge pull request #6784 from nicoddemus/deprecate-terminal-writer
Deprecate TerminalReporter.writer
This commit is contained in:
commit
ff7b5dbbde
|
@ -0,0 +1,3 @@
|
|||
The ``TerminalReporter.writer`` attribute has been deprecated and should no longer be used. This
|
||||
was inadvertently exposed as part of the public API of that plugin and ties it too much
|
||||
with ``py.io.TerminalWriter``.
|
|
@ -37,7 +37,7 @@ display captured output when tests fail: ``no``, ``stdout``, ``stderr``, ``log``
|
|||
Node Construction changed to ``Node.from_parent``
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. deprecated:: 5.3
|
||||
.. deprecated:: 5.4
|
||||
|
||||
The construction of nodes new should use the named constructor ``from_parent``.
|
||||
This limitation in api surface intends to enable better/simpler refactoring of the collection tree.
|
||||
|
@ -95,6 +95,18 @@ The plan is remove the ``--result-log`` option in pytest 6.0 if ``pytest-reportl
|
|||
to all users and is deemed stable. The ``pytest-reportlog`` plugin might even be merged into the core
|
||||
at some point, depending on the plans for the plugins and number of users using it.
|
||||
|
||||
TerminalReporter.writer
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. deprecated:: 5.4
|
||||
|
||||
The ``TerminalReporter.writer`` attribute has been deprecated and should no longer be used. This
|
||||
was inadvertently exposed as part of the public API of that plugin and ties it too much
|
||||
with ``py.io.TerminalWriter``.
|
||||
|
||||
Plugins that used ``TerminalReporter.writer`` directly should instead use ``TerminalReporter``
|
||||
methods that provide the same functionality.
|
||||
|
||||
|
||||
Removed Features
|
||||
----------------
|
||||
|
|
|
@ -8,6 +8,7 @@ import datetime
|
|||
import platform
|
||||
import sys
|
||||
import time
|
||||
import warnings
|
||||
from functools import partial
|
||||
from typing import Any
|
||||
from typing import Callable
|
||||
|
@ -25,6 +26,7 @@ from more_itertools import collapse
|
|||
|
||||
import pytest
|
||||
from _pytest import nodes
|
||||
from _pytest._io import TerminalWriter
|
||||
from _pytest.config import Config
|
||||
from _pytest.config import ExitCode
|
||||
from _pytest.main import Session
|
||||
|
@ -270,7 +272,7 @@ class TerminalReporter:
|
|||
self.startdir = config.invocation_dir
|
||||
if file is None:
|
||||
file = sys.stdout
|
||||
self.writer = self._tw = _pytest.config.create_terminal_writer(config, file)
|
||||
self._tw = _pytest.config.create_terminal_writer(config, file)
|
||||
self._screen_width = self._tw.fullwidth
|
||||
self.currentfspath = None # type: Any
|
||||
self.reportchars = getreportopt(config)
|
||||
|
@ -280,6 +282,16 @@ class TerminalReporter:
|
|||
self._show_progress_info = self._determine_show_progress_info()
|
||||
self._collect_report_last_write = None # type: Optional[float]
|
||||
|
||||
@property
|
||||
def writer(self) -> TerminalWriter:
|
||||
warnings.warn(
|
||||
pytest.PytestDeprecationWarning(
|
||||
"TerminalReporter.writer attribute is deprecated, use TerminalReporter._tw instead at your own risk.\n"
|
||||
"See https://docs.pytest.org/en/latest/deprecations.html#terminalreporter-writer for more information."
|
||||
)
|
||||
)
|
||||
return self._tw
|
||||
|
||||
def _determine_show_progress_info(self):
|
||||
"""Return True if we should display progress information based on the current config"""
|
||||
# do not show progress if we are not capturing output (#3038)
|
||||
|
@ -972,7 +984,7 @@ class TerminalReporter:
|
|||
failed = self.stats.get(stat, [])
|
||||
if not failed:
|
||||
return
|
||||
termwidth = self.writer.fullwidth
|
||||
termwidth = self._tw.fullwidth
|
||||
config = self.config
|
||||
for rep in failed:
|
||||
line = _get_line_with_reprcrash_message(config, rep, termwidth)
|
||||
|
|
|
@ -27,7 +27,7 @@ def test_resultlog_is_deprecated(testdir):
|
|||
|
||||
def test_terminal_reporter_writer_attr(pytestconfig):
|
||||
"""Check that TerminalReporter._tw is also available as 'writer' (#2984)
|
||||
This attribute is planned to be deprecated in 3.4.
|
||||
This attribute has been deprecated in 5.4.
|
||||
"""
|
||||
try:
|
||||
import xdist # noqa
|
||||
|
@ -36,7 +36,8 @@ def test_terminal_reporter_writer_attr(pytestconfig):
|
|||
except ImportError:
|
||||
pass
|
||||
terminal_reporter = pytestconfig.pluginmanager.get_plugin("terminalreporter")
|
||||
assert terminal_reporter.writer is terminal_reporter._tw
|
||||
with pytest.warns(pytest.PytestDeprecationWarning):
|
||||
assert terminal_reporter.writer is terminal_reporter._tw
|
||||
|
||||
|
||||
@pytest.mark.parametrize("plugin", sorted(deprecated.DEPRECATED_EXTERNAL_PLUGINS))
|
||||
|
|
Loading…
Reference in New Issue