88import platform
99import sys
1010import time
11+ import warnings
1112from functools import partial
1213from typing import Any
1314from typing import Callable
2526
2627import pytest
2728from _pytest import nodes
29+ from _pytest ._io import TerminalWriter
2830from _pytest .config import Config
2931from _pytest .config import ExitCode
3032from _pytest .main import Session
@@ -270,7 +272,7 @@ def __init__(self, config: Config, file=None) -> None:
270272 self .startdir = config .invocation_dir
271273 if file is None :
272274 file = sys .stdout
273- self .writer = self . _tw = _pytest .config .create_terminal_writer (config , file )
275+ self ._tw = _pytest .config .create_terminal_writer (config , file )
274276 self ._screen_width = self ._tw .fullwidth
275277 self .currentfspath = None # type: Any
276278 self .reportchars = getreportopt (config )
@@ -280,6 +282,16 @@ def __init__(self, config: Config, file=None) -> None:
280282 self ._show_progress_info = self ._determine_show_progress_info ()
281283 self ._collect_report_last_write = None # type: Optional[float]
282284
285+ @property
286+ def writer (self ) -> TerminalWriter :
287+ warnings .warn (
288+ pytest .PytestDeprecationWarning (
289+ "TerminalReporter.writer attribute is deprecated, use TerminalReporter._tw instead at your own risk.\n "
290+ "See https://docs.pytest.org/en/latest/deprecations.html#terminalreporter-writer for more information."
291+ )
292+ )
293+ return self ._tw
294+
283295 def _determine_show_progress_info (self ):
284296 """Return True if we should display progress information based on the current config"""
285297 # do not show progress if we are not capturing output (#3038)
@@ -972,7 +984,7 @@ def show_simple(stat, lines: List[str]) -> None:
972984 failed = self .stats .get (stat , [])
973985 if not failed :
974986 return
975- termwidth = self .writer .fullwidth
987+ termwidth = self ._tw .fullwidth
976988 config = self .config
977989 for rep in failed :
978990 line = _get_line_with_reprcrash_message (config , rep , termwidth )
0 commit comments