Skip to content

[WIP] Deprecate TerminalReporter.writer #2990

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions _pytest/deprecated.py
Original file line number Diff line number Diff line change
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.')
2 changes: 1 addition & 1 deletion _pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ def _getscopeitem(self, scope):
if node is None and scope == "class":
# fallback to function item itself
node = self._pyfuncitem
assert node
assert node, 'Could not obtain a node for scope "{}" for function {!r}'.format(scope, self._pyfuncitem)
return node

def __repr__(self):
Expand Down
12 changes: 12 additions & 0 deletions _pytest/terminal.py
Original file line number Diff line number Diff line change
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 @@ -153,6 +155,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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i propose to rename the internal property and trigger the deprecation also on the changing of self._tw to get bad players in line

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.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Bring back ``TerminalReporter.writer`` as an alias to ``TerminalReporter._tw``. This alias was removed by accident in the ``3.3.0`` release.
1 change: 1 addition & 0 deletions changelog/2984.removal
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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.
17 changes: 17 additions & 0 deletions testing/deprecated_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,23 @@ def test_func(i):
])


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')
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):
testdir.makepyfile("""
def test_func(pytestconfig):
Expand Down