Skip to content

Commit d3a65c7

Browse files
committed
Deprecate TerminalReporter.writer access
Related to pytest-dev#2984
1 parent e0fe11d commit d3a65c7

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

_pytest/deprecated.py

Lines changed: 3 additions & 0 deletions
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

Lines changed: 12 additions & 0 deletions
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)
163+
return self._tw
164+
165+
@writer.setter
166+
def writer(self, writer):
167+
warnings.warn(TERMINAL_REPORTER_WARNING)
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

Lines changed: 1 addition & 0 deletions
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.

testing/deprecated_test.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,16 @@ 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 3.4 (#2984)
107106
"""
108107
terminal_reporter = pytestconfig.pluginmanager.get_plugin('terminalreporter')
109-
assert terminal_reporter.writer is terminal_reporter._tw
108+
with pytest.deprecated_call():
109+
# getter
110+
_ = terminal_reporter.writer # noqa
111+
with pytest.deprecated_call():
112+
# setter
113+
terminal_reporter.writer = terminal_reporter._tw
110114

111115

112116
def test_pytest_catchlog_deprecated(testdir):

0 commit comments

Comments
 (0)