Merge pull request #2655 from nicoddemus/terminal-collecting-glitch
Fix small terminal glitch when collecting a single test item
This commit is contained in:
commit
12e60956de
|
@ -180,8 +180,22 @@ class TerminalReporter:
|
||||||
self._tw.line(line, **markup)
|
self._tw.line(line, **markup)
|
||||||
|
|
||||||
def rewrite(self, line, **markup):
|
def rewrite(self, line, **markup):
|
||||||
|
"""
|
||||||
|
Rewinds the terminal cursor to the beginning and writes the given line.
|
||||||
|
|
||||||
|
:kwarg erase: if True, will also add spaces until the full terminal width to ensure
|
||||||
|
previous lines are properly erased.
|
||||||
|
|
||||||
|
The rest of the keyword arguments are markup instructions.
|
||||||
|
"""
|
||||||
|
erase = markup.pop('erase', False)
|
||||||
|
if erase:
|
||||||
|
fill_count = self._tw.fullwidth - len(line)
|
||||||
|
fill = ' ' * fill_count
|
||||||
|
else:
|
||||||
|
fill = ''
|
||||||
line = str(line)
|
line = str(line)
|
||||||
self._tw.write("\r" + line, **markup)
|
self._tw.write("\r" + line + fill, **markup)
|
||||||
|
|
||||||
def write_sep(self, sep, title=None, **markup):
|
def write_sep(self, sep, title=None, **markup):
|
||||||
self.ensure_newline()
|
self.ensure_newline()
|
||||||
|
@ -292,12 +306,9 @@ class TerminalReporter:
|
||||||
if skipped:
|
if skipped:
|
||||||
line += " / %d skipped" % skipped
|
line += " / %d skipped" % skipped
|
||||||
if self.isatty:
|
if self.isatty:
|
||||||
|
self.rewrite(line, bold=True, erase=True)
|
||||||
if final:
|
if final:
|
||||||
line += " \n"
|
self.write('\n')
|
||||||
# Rewrite with empty line so we will not see the artifact of
|
|
||||||
# previous write
|
|
||||||
self.rewrite('')
|
|
||||||
self.rewrite(line, bold=True)
|
|
||||||
else:
|
else:
|
||||||
self.write_line(line)
|
self.write_line(line)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Fixed small terminal glitch when collecting a single test item.
|
|
@ -214,6 +214,16 @@ class TestTerminal(object):
|
||||||
result = testdir.runpytest()
|
result = testdir.runpytest()
|
||||||
result.stdout.fnmatch_lines(['collected 1 item'])
|
result.stdout.fnmatch_lines(['collected 1 item'])
|
||||||
|
|
||||||
|
def test_rewrite(self, testdir, monkeypatch):
|
||||||
|
config = testdir.parseconfig()
|
||||||
|
f = py.io.TextIO()
|
||||||
|
monkeypatch.setattr(f, 'isatty', lambda *args: True)
|
||||||
|
tr = TerminalReporter(config, f)
|
||||||
|
tr.writer.fullwidth = 10
|
||||||
|
tr.write('hello')
|
||||||
|
tr.rewrite('hey', erase=True)
|
||||||
|
assert f.getvalue() == 'hello' + '\r' + 'hey' + (7 * ' ')
|
||||||
|
|
||||||
|
|
||||||
class TestCollectonly(object):
|
class TestCollectonly(object):
|
||||||
def test_collectonly_basic(self, testdir):
|
def test_collectonly_basic(self, testdir):
|
||||||
|
|
Loading…
Reference in New Issue