Skip to content

Commit

Permalink
Deprecate TerminalReporter.writer access
Browse files Browse the repository at this point in the history
Related to pytest-dev#2984
  • Loading branch information
nicoddemus committed Nov 30, 2017
1 parent cf0cac3 commit 7dd1c3c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 5 deletions.
3 changes: 3 additions & 0 deletions _pytest/deprecated.py
Expand Up @@ -50,3 +50,6 @@ class RemovedInPytest4Warning(DeprecationWarning):
"Metafunc.addcall is deprecated and scheduled to be removed in pytest 4.0.\n"
"Please use Metafunc.parametrize instead."
)

TERMINAL_REPORTER_WARNING = RemovedInPytest4Warning('The "writer" attribute is deprecated and '
'will be removed in a future release.')
12 changes: 12 additions & 0 deletions _pytest/terminal.py
Expand Up @@ -8,13 +8,15 @@
import platform
import sys
import time
import warnings

import pluggy
import py
import six

import pytest
from _pytest import nodes
from _pytest.deprecated import TERMINAL_REPORTER_WARNING
from _pytest.main import EXIT_OK, EXIT_TESTSFAILED, EXIT_INTERRUPTED, \
EXIT_USAGEERROR, EXIT_NOTESTSCOLLECTED

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

@property
def writer(self):
warnings.warn(TERMINAL_REPORTER_WARNING, stacklevel=2)
return self._tw

@writer.setter
def writer(self, writer):
warnings.warn(TERMINAL_REPORTER_WARNING, stacklevel=2)
self._tw = writer

def hasopt(self, char):
char = {'xfailed': 'x', 'skipped': 's'}.get(char, char)
return char in self.reportchars
Expand Down
1 change: 1 addition & 0 deletions changelog/2984.removal
@@ -0,0 +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.
6 changes: 5 additions & 1 deletion doc/en/backwards-compatibility.rst
Expand Up @@ -79,6 +79,10 @@ Use ``[tool:pytest]`` instead for compatibility with other tools.

Deprecated in ``3.0``.

**TerminalReporter.writer**

This attribute was never meant to be part of the public API and has been deprecated in ``3.4``.

Past Releases
~~~~~~~~~~~~~

Expand All @@ -102,4 +106,4 @@ Past Releases
3.3
^^^

* Dropped support for EOL Python 2.6 and 3.3.
* Dropped support for EOL Python 2.6 and 3.3.
12 changes: 8 additions & 4 deletions testing/deprecated_test.py
Expand Up @@ -101,17 +101,21 @@ def test_func(i):
])


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.
def test_terminal_reporter_writer_deprecated(pytestconfig):
"""TerminalReporter.writer is deprecated and meant to be removed in a future release (#2984)
"""
try:
import xdist # noqa
pytest.skip('xdist workers disable the terminal reporter plugin')
except ImportError:
pass
terminal_reporter = pytestconfig.pluginmanager.get_plugin('terminalreporter')
assert terminal_reporter.writer is terminal_reporter._tw
with pytest.deprecated_call():
# getter
_ = terminal_reporter.writer # noqa
with pytest.deprecated_call():
# setter
terminal_reporter.writer = terminal_reporter._tw


def test_pytest_catchlog_deprecated(testdir):
Expand Down

0 comments on commit 7dd1c3c

Please sign in to comment.