From 3b4bdc72e98f89b80564f3579bf66465f3bd5568 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 30 Nov 2017 18:44:18 -0200 Subject: [PATCH] Deprecate TerminalReporter.writer access Related to #2984 --- _pytest/deprecated.py | 3 +++ _pytest/terminal.py | 12 ++++++++++++ changelog/2984.removal | 1 + testing/deprecated_test.py | 12 ++++++++---- 4 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 changelog/2984.removal diff --git a/_pytest/deprecated.py b/_pytest/deprecated.py index 9c0fbeca7bc..7d320722c76 100644 --- a/_pytest/deprecated.py +++ b/_pytest/deprecated.py @@ -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.') diff --git a/_pytest/terminal.py b/_pytest/terminal.py index ca9b6e8e7ee..35d8a305bbf 100644 --- a/_pytest/terminal.py +++ b/_pytest/terminal.py @@ -8,6 +8,7 @@ import platform import sys import time +import warnings import pluggy import py @@ -15,6 +16,7 @@ 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 @@ -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 diff --git a/changelog/2984.removal b/changelog/2984.removal new file mode 100644 index 00000000000..378208b2f2a --- /dev/null +++ b/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. diff --git a/testing/deprecated_test.py b/testing/deprecated_test.py index cb52a337f16..1c62a854f96 100644 --- a/testing/deprecated_test.py +++ b/testing/deprecated_test.py @@ -101,12 +101,16 @@ 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 3.4 (#2984) """ 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):