From c8cc18a9a10bfbaf251aab1714b8647b3c612932 Mon Sep 17 00:00:00 2001 From: feuillemorte Date: Tue, 10 Apr 2018 22:22:24 +0300 Subject: [PATCH 1/6] #3374 Added support for long file names --- _pytest/terminal.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/_pytest/terminal.py b/_pytest/terminal.py index f8ad33c1010..0bff723a229 100644 --- a/_pytest/terminal.py +++ b/_pytest/terminal.py @@ -215,7 +215,16 @@ def write_fspath_result(self, nodeid, res): self.currentfspath = fspath fspath = self.startdir.bestrelpath(fspath) self._tw.line() - self._tw.write(fspath + " ") + if len(fspath) > (self._tw.fullwidth - self._tw.chars_on_current_line - 10): + line = self._tw.fullwidth - self._tw.chars_on_current_line - 10 + while len(fspath) > 0: + self._tw.write(fspath[:line] + " ") + fspath = fspath[line:] + if not fspath: + break + self._tw.line() + else: + self._tw.write(fspath + " ") self._tw.write(res) def write_ensure_prefix(self, prefix, extra="", **kwargs): From 0514142f653a40508351d6125310d13f3dce7f87 Mon Sep 17 00:00:00 2001 From: feuillemorte Date: Tue, 10 Apr 2018 22:22:39 +0300 Subject: [PATCH 2/6] #3374 Added test --- testing/test_terminal.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/testing/test_terminal.py b/testing/test_terminal.py index 8ef25062eb1..d3dd6f334be 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -1063,6 +1063,29 @@ def test_foobar(i): pass """, ) + @pytest.fixture + def many_tests_files_long_names(self, testdir): + testdir.makepyfile( + test_bar_with_very_long_name_bar_with_very_long_name_bar_with_very_long_name_with_very_long_name=""" + import pytest + @pytest.mark.parametrize('i', range(10)) + def test_bar(i): + pass + """, + test_foo_with_very_long_name_foo_with_very_long_name_foo_with_very_long_name_with_very_long_name=""" + import pytest + @pytest.mark.parametrize('i', range(5)) + def test_foo(i): + pass + """, + test_fooba_with_very_long_name_foobar_with_very_long_name_foobar_with_very_long_name_with_very_long_name=""" + import pytest + @pytest.mark.parametrize('i', range(5)) + def test_foobar(i): + pass + """, + ) + def test_zero_tests_collected(self, testdir): """Some plugins (testmon for example) might issue pytest_runtest_logreport without any tests being actually collected (#2971).""" @@ -1089,6 +1112,17 @@ def test_normal(self, many_tests_files, testdir): r'test_foobar.py \.{5} \s+ \[100%\]', ]) + def test_normal_long_names(self, many_tests_files_long_names, testdir): + output = testdir.runpytest() + output.stdout.fnmatch_lines([ + '*test_bar_with*', + '*long_name.py* 50%]', + '*test_foo_with*', + '*long_name.py* 75%]', + '*test_fooba_with*', + '*long_name.py*100%]', + ]) + def test_verbose(self, many_tests_files, testdir): output = testdir.runpytest('-v') output.stdout.re_match_lines([ From a63f37b85570d85f40f7c80bb7635f2e1aac2b9a Mon Sep 17 00:00:00 2001 From: feuillemorte Date: Tue, 10 Apr 2018 22:22:53 +0300 Subject: [PATCH 3/6] #3374 Added changelog --- changelog/3374.feature | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/3374.feature diff --git a/changelog/3374.feature b/changelog/3374.feature new file mode 100644 index 00000000000..130adeb294d --- /dev/null +++ b/changelog/3374.feature @@ -0,0 +1 @@ +If path name is very long then pytest will split name for several lines. From 30925cf6baf7167c3e10ffe127f306528279f2da Mon Sep 17 00:00:00 2001 From: feuillemorte Date: Fri, 13 Apr 2018 18:05:00 +0300 Subject: [PATCH 4/6] #3374 Fix comments --- _pytest/terminal.py | 27 +++++++++++++++------------ testing/test_terminal.py | 34 ---------------------------------- 2 files changed, 15 insertions(+), 46 deletions(-) diff --git a/_pytest/terminal.py b/_pytest/terminal.py index 0bff723a229..ff260df9c19 100644 --- a/_pytest/terminal.py +++ b/_pytest/terminal.py @@ -186,6 +186,7 @@ def __init__(self, config, file=None): # self.writer will be deprecated in pytest-3.4 self.writer = self._tw self._screen_width = self._tw.fullwidth + self.is_fspath_extra_width = False self.currentfspath = None self.reportchars = getreportopt(config) self.hasmarkup = self._tw.hasmarkup @@ -215,16 +216,12 @@ def write_fspath_result(self, nodeid, res): self.currentfspath = fspath fspath = self.startdir.bestrelpath(fspath) self._tw.line() - if len(fspath) > (self._tw.fullwidth - self._tw.chars_on_current_line - 10): - line = self._tw.fullwidth - self._tw.chars_on_current_line - 10 - while len(fspath) > 0: - self._tw.write(fspath[:line] + " ") - fspath = fspath[line:] - if not fspath: - break - self._tw.line() - else: - self._tw.write(fspath + " ") + self._tw.write(fspath + " ") + width = self._tw.fullwidth - self._tw.chars_on_current_line + if 0 < width < 10: + self._tw.line() + elif width < 0: + self.is_fspath_extra_width = True self._tw.write(res) def write_ensure_prefix(self, prefix, extra="", **kwargs): @@ -364,7 +361,10 @@ def pytest_runtest_logfinish(self, nodeid): self._write_progress_information_filling_space() else: past_edge = self._tw.chars_on_current_line + self._PROGRESS_LENGTH + 1 >= self._screen_width - if past_edge: + width = self._tw.chars_on_current_line % self._screen_width + 9 + if past_edge and self.is_fspath_extra_width and width >= self._screen_width: + self.is_fspath_extra_width = False + elif past_edge and not self.is_fspath_extra_width: msg = self._get_progress_information_message() self._tw.write(msg + '\n', cyan=True) @@ -381,7 +381,10 @@ def _get_progress_information_message(self): def _write_progress_information_filling_space(self): msg = self._get_progress_information_message() - fill = ' ' * (self._tw.fullwidth - self._tw.chars_on_current_line - len(msg) - 1) + if self.is_fspath_extra_width: + fill = ' ' * (self._tw.fullwidth - self._tw.chars_on_current_line % self._screen_width - len(msg) - 1) + else: + fill = ' ' * (self._tw.fullwidth - self._tw.chars_on_current_line - len(msg) - 1) self.write(fill + msg, cyan=True) def pytest_collection(self): diff --git a/testing/test_terminal.py b/testing/test_terminal.py index d3dd6f334be..8ef25062eb1 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -1063,29 +1063,6 @@ def test_foobar(i): pass """, ) - @pytest.fixture - def many_tests_files_long_names(self, testdir): - testdir.makepyfile( - test_bar_with_very_long_name_bar_with_very_long_name_bar_with_very_long_name_with_very_long_name=""" - import pytest - @pytest.mark.parametrize('i', range(10)) - def test_bar(i): - pass - """, - test_foo_with_very_long_name_foo_with_very_long_name_foo_with_very_long_name_with_very_long_name=""" - import pytest - @pytest.mark.parametrize('i', range(5)) - def test_foo(i): - pass - """, - test_fooba_with_very_long_name_foobar_with_very_long_name_foobar_with_very_long_name_with_very_long_name=""" - import pytest - @pytest.mark.parametrize('i', range(5)) - def test_foobar(i): - pass - """, - ) - def test_zero_tests_collected(self, testdir): """Some plugins (testmon for example) might issue pytest_runtest_logreport without any tests being actually collected (#2971).""" @@ -1112,17 +1089,6 @@ def test_normal(self, many_tests_files, testdir): r'test_foobar.py \.{5} \s+ \[100%\]', ]) - def test_normal_long_names(self, many_tests_files_long_names, testdir): - output = testdir.runpytest() - output.stdout.fnmatch_lines([ - '*test_bar_with*', - '*long_name.py* 50%]', - '*test_foo_with*', - '*long_name.py* 75%]', - '*test_fooba_with*', - '*long_name.py*100%]', - ]) - def test_verbose(self, many_tests_files, testdir): output = testdir.runpytest('-v') output.stdout.re_match_lines([ From 0ed67c77c70cab1332cb5345d0a4f4debfcd5c42 Mon Sep 17 00:00:00 2001 From: feuillemorte Date: Fri, 13 Apr 2018 18:39:01 +0300 Subject: [PATCH 5/6] #3374 Fix bug --- _pytest/terminal.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/_pytest/terminal.py b/_pytest/terminal.py index ff260df9c19..901c4d9bde1 100644 --- a/_pytest/terminal.py +++ b/_pytest/terminal.py @@ -218,7 +218,7 @@ def write_fspath_result(self, nodeid, res): self._tw.line() self._tw.write(fspath + " ") width = self._tw.fullwidth - self._tw.chars_on_current_line - if 0 < width < 10: + if 0 < width < 10 or self._tw.chars_on_current_line % self._screen_width > self._screen_width - 10: self._tw.line() elif width < 0: self.is_fspath_extra_width = True @@ -383,6 +383,7 @@ def _write_progress_information_filling_space(self): msg = self._get_progress_information_message() if self.is_fspath_extra_width: fill = ' ' * (self._tw.fullwidth - self._tw.chars_on_current_line % self._screen_width - len(msg) - 1) + self.is_fspath_extra_width = False else: fill = ' ' * (self._tw.fullwidth - self._tw.chars_on_current_line - len(msg) - 1) self.write(fill + msg, cyan=True) From b9ebffb14566536da15b213f12b3d4a4cf0eaadb Mon Sep 17 00:00:00 2001 From: feuillemorte Date: Fri, 27 Apr 2018 22:36:36 +0300 Subject: [PATCH 6/6] #3374 fix comments --- _pytest/terminal.py | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/_pytest/terminal.py b/_pytest/terminal.py index 901c4d9bde1..531f24996e8 100644 --- a/_pytest/terminal.py +++ b/_pytest/terminal.py @@ -186,7 +186,7 @@ def __init__(self, config, file=None): # self.writer will be deprecated in pytest-3.4 self.writer = self._tw self._screen_width = self._tw.fullwidth - self.is_fspath_extra_width = False + self._is_fspath_past_edge = False self.currentfspath = None self.reportchars = getreportopt(config) self.hasmarkup = self._tw.hasmarkup @@ -217,11 +217,11 @@ def write_fspath_result(self, nodeid, res): fspath = self.startdir.bestrelpath(fspath) self._tw.line() self._tw.write(fspath + " ") - width = self._tw.fullwidth - self._tw.chars_on_current_line - if 0 < width < 10 or self._tw.chars_on_current_line % self._screen_width > self._screen_width - 10: + + if self._screen_width - self._MAX_LEN_LEFT <= self._tw.chars_on_current_line % self._screen_width: self._tw.line() - elif width < 0: - self.is_fspath_extra_width = True + if self._tw.fullwidth - self._tw.chars_on_current_line < 0: + self._is_fspath_past_edge = True self._tw.write(res) def write_ensure_prefix(self, prefix, extra="", **kwargs): @@ -361,13 +361,26 @@ def pytest_runtest_logfinish(self, nodeid): self._write_progress_information_filling_space() else: past_edge = self._tw.chars_on_current_line + self._PROGRESS_LENGTH + 1 >= self._screen_width - width = self._tw.chars_on_current_line % self._screen_width + 9 - if past_edge and self.is_fspath_extra_width and width >= self._screen_width: - self.is_fspath_extra_width = False - elif past_edge and not self.is_fspath_extra_width: - msg = self._get_progress_information_message() - self._tw.write(msg + '\n', cyan=True) - + width = self._tw.chars_on_current_line % self._screen_width + self._MAX_LEN_LEFT + 1 + # if past_edge and self.is_fspath_extra_width and width >= self._screen_width: + if past_edge: + if self._is_fspath_past_edge and width > self._screen_width: + self._is_fspath_past_edge = False + # print('HEY') + # msg = self._get_progress_information_message() + # self._tw.write(msg + '\n', cyan=True) + # elif not self.is_fspath_extra_width: + if not self._is_fspath_past_edge: + msg = self._get_progress_information_message() + self._tw.write(msg + '\n', cyan=True) + # if not self.is_fspath_extra_width: + # msg = self._get_progress_information_message() + # self._tw.write(msg + '\n', cyan=True) + # elif past_edge and not self.is_fspath_extra_width: + # msg = self._get_progress_information_message() + # self._tw.write(msg + '\n', cyan=True) + + _MAX_LEN_LEFT = len('. [ 80%]') _PROGRESS_LENGTH = len(' [100%]') def _get_progress_information_message(self): @@ -381,9 +394,9 @@ def _get_progress_information_message(self): def _write_progress_information_filling_space(self): msg = self._get_progress_information_message() - if self.is_fspath_extra_width: + if self._is_fspath_past_edge: fill = ' ' * (self._tw.fullwidth - self._tw.chars_on_current_line % self._screen_width - len(msg) - 1) - self.is_fspath_extra_width = False + self._is_fspath_past_edge = False else: fill = ' ' * (self._tw.fullwidth - self._tw.chars_on_current_line - len(msg) - 1) self.write(fill + msg, cyan=True)