From 70f1e3b4b0cdcf428fdcf44b6bc62ad76e2a03b2 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 30 Nov 2017 07:47:00 -0200 Subject: [PATCH 1/3] Improve getscopeitem assertion message Fix #2979 --- _pytest/fixtures.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_pytest/fixtures.py b/_pytest/fixtures.py index 19b977224cf..e09ffaddba7 100644 --- a/_pytest/fixtures.py +++ b/_pytest/fixtures.py @@ -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): From cf0cac3b734dd47c8f6cbf3afa759231fbb76bc9 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 30 Nov 2017 18:34:53 -0200 Subject: [PATCH 2/3] Bring back TerminalReporter.writer as an alias to TerminalReporter._tw Fix #2984 --- _pytest/terminal.py | 2 ++ changelog/2984.bugfix | 1 + testing/deprecated_test.py | 13 +++++++++++++ 3 files changed, 16 insertions(+) create mode 100644 changelog/2984.bugfix diff --git a/_pytest/terminal.py b/_pytest/terminal.py index 8538ee6aa2e..ca9b6e8e7ee 100644 --- a/_pytest/terminal.py +++ b/_pytest/terminal.py @@ -145,6 +145,8 @@ def __init__(self, config, file=None): if file is None: file = sys.stdout self._tw = _pytest.config.create_terminal_writer(config, file) + # self.writer will be deprecated in pytest-3.4 + self.writer = self._tw self._screen_width = self._tw.fullwidth self.currentfspath = None self.reportchars = getreportopt(config) diff --git a/changelog/2984.bugfix b/changelog/2984.bugfix new file mode 100644 index 00000000000..21f5748d523 --- /dev/null +++ b/changelog/2984.bugfix @@ -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. diff --git a/testing/deprecated_test.py b/testing/deprecated_test.py index f3c40cb3dbb..11c4ad43cbc 100644 --- a/testing/deprecated_test.py +++ b/testing/deprecated_test.py @@ -101,6 +101,19 @@ 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. + """ + 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 + + def test_pytest_catchlog_deprecated(testdir): testdir.makepyfile(""" def test_func(pytestconfig): From b2f9844cb7ca0e610b1667eea3faa86f98251961 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Thu, 30 Nov 2017 18:44:18 -0200 Subject: [PATCH 3/3] Deprecate TerminalReporter.writer access Related to #2984 --- _pytest/deprecated.py | 3 +++ _pytest/terminal.py | 14 ++++++++++++-- changelog/2984.removal | 1 + doc/en/backwards-compatibility.rst | 6 +++++- testing/deprecated_test.py | 12 ++++++++---- 5 files changed, 29 insertions(+), 7 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..6b9aaaaf1ba 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 @@ -145,8 +147,6 @@ def __init__(self, config, file=None): if file is None: file = sys.stdout self._tw = _pytest.config.create_terminal_writer(config, file) - # self.writer will be deprecated in pytest-3.4 - self.writer = self._tw self._screen_width = self._tw.fullwidth self.currentfspath = None self.reportchars = getreportopt(config) @@ -155,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) + 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/doc/en/backwards-compatibility.rst b/doc/en/backwards-compatibility.rst index 84f2c43edaa..288274a9416 100644 --- a/doc/en/backwards-compatibility.rst +++ b/doc/en/backwards-compatibility.rst @@ -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 ~~~~~~~~~~~~~ @@ -102,4 +106,4 @@ Past Releases 3.3 ^^^ -* Dropped support for EOL Python 2.6 and 3.3. \ No newline at end of file +* Dropped support for EOL Python 2.6 and 3.3. diff --git a/testing/deprecated_test.py b/testing/deprecated_test.py index 11c4ad43cbc..ee4cf7a70ec 100644 --- a/testing/deprecated_test.py +++ b/testing/deprecated_test.py @@ -101,9 +101,8 @@ 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 @@ -111,7 +110,12 @@ def test_terminal_reporter_writer_attr(pytestconfig): 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):