Skip to content

Commit 7dd1c3c

Browse files
committed
Deprecate TerminalReporter.writer access
Related to pytest-dev#2984
1 parent cf0cac3 commit 7dd1c3c

File tree

5 files changed

+29
-5
lines changed

5 files changed

+29
-5
lines changed

_pytest/deprecated.py

+3
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,6 @@ class RemovedInPytest4Warning(DeprecationWarning):
5050
"Metafunc.addcall is deprecated and scheduled to be removed in pytest 4.0.\n"
5151
"Please use Metafunc.parametrize instead."
5252
)
53+
54+
TERMINAL_REPORTER_WARNING = RemovedInPytest4Warning('The "writer" attribute is deprecated and '
55+
'will be removed in a future release.')

_pytest/terminal.py

+12
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
import platform
99
import sys
1010
import time
11+
import warnings
1112

1213
import pluggy
1314
import py
1415
import six
1516

1617
import pytest
1718
from _pytest import nodes
19+
from _pytest.deprecated import TERMINAL_REPORTER_WARNING
1820
from _pytest.main import EXIT_OK, EXIT_TESTSFAILED, EXIT_INTERRUPTED, \
1921
EXIT_USAGEERROR, EXIT_NOTESTSCOLLECTED
2022

@@ -155,6 +157,16 @@ def __init__(self, config, file=None):
155157
self._progress_items_reported = 0
156158
self._show_progress_info = self.config.getini('console_output_style') == 'progress'
157159

160+
@property
161+
def writer(self):
162+
warnings.warn(TERMINAL_REPORTER_WARNING, stacklevel=2)
163+
return self._tw
164+
165+
@writer.setter
166+
def writer(self, writer):
167+
warnings.warn(TERMINAL_REPORTER_WARNING, stacklevel=2)
168+
self._tw = writer
169+
158170
def hasopt(self, char):
159171
char = {'xfailed': 'x', 'skipped': 's'}.get(char, char)
160172
return char in self.reportchars

changelog/2984.removal

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
``TerminalReporter.writer`` has been deprecated and will be removed in a future release. This attribute is an internal API which was not meant to be exposed as public, if needed use the functions of ``TerminalReporter`` directly.

doc/en/backwards-compatibility.rst

+5-1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ Use ``[tool:pytest]`` instead for compatibility with other tools.
7979

8080
Deprecated in ``3.0``.
8181

82+
**TerminalReporter.writer**
83+
84+
This attribute was never meant to be part of the public API and has been deprecated in ``3.4``.
85+
8286
Past Releases
8387
~~~~~~~~~~~~~
8488

@@ -102,4 +106,4 @@ Past Releases
102106
3.3
103107
^^^
104108

105-
* Dropped support for EOL Python 2.6 and 3.3.
109+
* Dropped support for EOL Python 2.6 and 3.3.

testing/deprecated_test.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,21 @@ def test_func(i):
101101
])
102102

103103

104-
def test_terminal_reporter_writer_attr(pytestconfig):
105-
"""Check that TerminalReporter._tw is also available as 'writer' (#2984)
106-
This attribute is planned to be deprecated in 3.4.
104+
def test_terminal_reporter_writer_deprecated(pytestconfig):
105+
"""TerminalReporter.writer is deprecated and meant to be removed in a future release (#2984)
107106
"""
108107
try:
109108
import xdist # noqa
110109
pytest.skip('xdist workers disable the terminal reporter plugin')
111110
except ImportError:
112111
pass
113112
terminal_reporter = pytestconfig.pluginmanager.get_plugin('terminalreporter')
114-
assert terminal_reporter.writer is terminal_reporter._tw
113+
with pytest.deprecated_call():
114+
# getter
115+
_ = terminal_reporter.writer # noqa
116+
with pytest.deprecated_call():
117+
# setter
118+
terminal_reporter.writer = terminal_reporter._tw
115119

116120

117121
def test_pytest_catchlog_deprecated(testdir):

0 commit comments

Comments
 (0)