Skip to content

Commit

Permalink
Merge pull request pytest-dev#6986 from RonnyPfannschmidt/fix-6951-tw…
Browse files Browse the repository at this point in the history
….writer-writable

fix pytest-dev#6951: allow to write TerminalReporter.writer
  • Loading branch information
RonnyPfannschmidt committed Apr 10, 2020
1 parent 554f600 commit 38a4c7e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
1 change: 1 addition & 0 deletions changelog/6951.bugfix.rst
@@ -0,0 +1 @@
Allow users to still set the deprecated ``TerminalReporter.writer`` attribute.
6 changes: 6 additions & 0 deletions src/_pytest/deprecated.py
Expand Up @@ -54,3 +54,9 @@
"The pytest_collect_directory hook is not working.\n"
"Please use collect_ignore in conftests or pytest_collection_modifyitems."
)


TERMINALWRITER_WRITER = PytestDeprecationWarning(
"The TerminalReporter.writer attribute is deprecated, use TerminalReporter._tw instead at your own risk.\n"
"See https://docs.pytest.org/en/latest/deprecations.html#terminalreporter-writer for more information."
)
13 changes: 7 additions & 6 deletions src/_pytest/terminal.py
Expand Up @@ -29,6 +29,7 @@
from _pytest._io import TerminalWriter
from _pytest.config import Config
from _pytest.config import ExitCode
from _pytest.deprecated import TERMINALWRITER_WRITER
from _pytest.main import Session
from _pytest.reports import CollectReport
from _pytest.reports import TestReport
Expand Down Expand Up @@ -284,14 +285,14 @@ def __init__(self, config: Config, file=None) -> None:

@property
def writer(self) -> TerminalWriter:
warnings.warn(
pytest.PytestDeprecationWarning(
"TerminalReporter.writer attribute is deprecated, use TerminalReporter._tw instead at your own risk.\n"
"See https://docs.pytest.org/en/latest/deprecations.html#terminalreporter-writer for more information."
)
)
warnings.warn(TERMINALWRITER_WRITER, stacklevel=2)
return self._tw

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

def _determine_show_progress_info(self):
"""Return True if we should display progress information based on the current config"""
# do not show progress if we are not capturing output (#3038)
Expand Down
9 changes: 8 additions & 1 deletion testing/deprecated_test.py
Expand Up @@ -36,8 +36,15 @@ def test_terminal_reporter_writer_attr(pytestconfig):
except ImportError:
pass
terminal_reporter = pytestconfig.pluginmanager.get_plugin("terminalreporter")
expected_tw = terminal_reporter._tw

with pytest.warns(pytest.PytestDeprecationWarning):
assert terminal_reporter.writer is expected_tw

with pytest.warns(pytest.PytestDeprecationWarning):
assert terminal_reporter.writer is terminal_reporter._tw
terminal_reporter.writer = expected_tw

assert terminal_reporter._tw is expected_tw


@pytest.mark.parametrize("plugin", sorted(deprecated.DEPRECATED_EXTERNAL_PLUGINS))
Expand Down

0 comments on commit 38a4c7e

Please sign in to comment.