summaryrefslogtreecommitdiff
path: root/src/_pytest/_io
diff options
context:
space:
mode:
authorRan Benita <ran@unusedvar.com>2020-04-29 18:14:57 +0300
committerRan Benita <ran@unusedvar.com>2020-04-30 16:44:03 +0300
commitd5584c7207e094aa833358285f749e01f907aa00 (patch)
treea84c11fb2577c7e23badce1ba10a02d7442d1c2e /src/_pytest/_io
parentdd32c72ff0a9b875e3efbd31e28d63feaac8f32d (diff)
downloadpytest-d5584c7207e094aa833358285f749e01f907aa00.tar.gz
terminalwriter: compute width_of_current_line lazily
Currently this property is computed eagerly, which means get_line_width() is computed on everything written, but that is a slow function. Compute it lazily, so that get_line_width() only runs when needed.
Diffstat (limited to 'src/_pytest/_io')
-rw-r--r--src/_pytest/_io/terminalwriter.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/_pytest/_io/terminalwriter.py b/src/_pytest/_io/terminalwriter.py
index 124ffe795..204222c88 100644
--- a/src/_pytest/_io/terminalwriter.py
+++ b/src/_pytest/_io/terminalwriter.py
@@ -83,7 +83,7 @@ class TerminalWriter:
assert file is not None
self._file = file
self.hasmarkup = should_do_markup(file)
- self._width_of_current_line = 0
+ self._current_line = ""
self._terminal_width = None # type: Optional[int]
@property
@@ -99,7 +99,7 @@ class TerminalWriter:
@property
def width_of_current_line(self) -> int:
"""Return an estimate of the width so far in the current line."""
- return self._width_of_current_line
+ return get_line_width(self._current_line)
def markup(self, text: str, **kw: bool) -> str:
esc = []
@@ -153,9 +153,9 @@ class TerminalWriter:
if msg:
current_line = msg.rsplit("\n", 1)[-1]
if "\n" in msg:
- self._width_of_current_line = get_line_width(current_line)
+ self._current_line = current_line
else:
- self._width_of_current_line += get_line_width(current_line)
+ self._current_line += current_line
if self.hasmarkup and kw:
markupmsg = self.markup(msg, **kw)