Skip to content

Commit 8d8e68c

Browse files
authored
Merge pull request #3911 from wimglenn/i18n_width
improve line width estimate
2 parents 019e33e + 19fa01b commit 8d8e68c

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

changelog/3911.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Terminal writer now takes into account unicode character width when writing out progress.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def get_environment_marker_support_level():
5959
def main():
6060
extras_require = {}
6161
install_requires = [
62-
"py>=1.5.0",
62+
"py>=1.5.0", # if py gets upgrade to >=1.6, remove _width_of_current_line in terminal.py
6363
"six>=1.10.0",
6464
"setuptools",
6565
"attrs>=17.4.0",

src/_pytest/terminal.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,8 @@ def pytest_runtest_logfinish(self, nodeid):
412412
if last_item:
413413
self._write_progress_information_filling_space()
414414
else:
415-
past_edge = (
416-
self._tw.chars_on_current_line + self._PROGRESS_LENGTH + 1
417-
>= self._screen_width
418-
)
415+
w = self._width_of_current_line
416+
past_edge = w + self._PROGRESS_LENGTH + 1 >= self._screen_width
419417
if past_edge:
420418
msg = self._get_progress_information_message()
421419
self._tw.write(msg + "\n", cyan=True)
@@ -433,10 +431,18 @@ def _get_progress_information_message(self):
433431

434432
def _write_progress_information_filling_space(self):
435433
msg = self._get_progress_information_message()
436-
fill = " " * (
437-
self._tw.fullwidth - self._tw.chars_on_current_line - len(msg) - 1
438-
)
439-
self.write(fill + msg, cyan=True)
434+
w = self._width_of_current_line
435+
fill = self._tw.fullwidth - w - 1
436+
self.write(msg.rjust(fill), cyan=True)
437+
438+
@property
439+
def _width_of_current_line(self):
440+
"""Return the width of current line, using the superior implementation of py-1.6 when available"""
441+
try:
442+
return self._tw.width_of_current_line
443+
except AttributeError:
444+
# py < 1.6.0
445+
return self._tw.chars_on_current_line
440446

441447
def pytest_collection(self):
442448
if not self.isatty and self.config.option.verbose >= 1:

0 commit comments

Comments
 (0)