terminalwriter: remove TerminalWriter's stringio argument
Had a mark indicating it should be removed, and I agree, it's better to just use the `file` argument.
This commit is contained in:
parent
94a57d2353
commit
66ee755649
|
@ -4,7 +4,6 @@ import shutil
|
||||||
import sys
|
import sys
|
||||||
import unicodedata
|
import unicodedata
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
from io import StringIO
|
|
||||||
from typing import Sequence
|
from typing import Sequence
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,13 +82,9 @@ class TerminalWriter:
|
||||||
invert=7,
|
invert=7,
|
||||||
)
|
)
|
||||||
|
|
||||||
# XXX deprecate stringio argument
|
def __init__(self, file=None):
|
||||||
def __init__(self, file=None, stringio=False):
|
|
||||||
if file is None:
|
if file is None:
|
||||||
if stringio:
|
file = sys.stdout
|
||||||
self.stringio = file = StringIO()
|
|
||||||
else:
|
|
||||||
from sys import stdout as file
|
|
||||||
if hasattr(file, "isatty") and file.isatty() and colorama:
|
if hasattr(file, "isatty") and file.isatty() and colorama:
|
||||||
file = colorama.AnsiToWin32(file).stream
|
file = colorama.AnsiToWin32(file).stream
|
||||||
self._file = file
|
self._file = file
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
""" submit failure or test session information to a pastebin service. """
|
""" submit failure or test session information to a pastebin service. """
|
||||||
import tempfile
|
import tempfile
|
||||||
|
from io import StringIO
|
||||||
from typing import IO
|
from typing import IO
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -99,11 +100,10 @@ def pytest_terminal_summary(terminalreporter):
|
||||||
msg = rep.longrepr.reprtraceback.reprentries[-1].reprfileloc
|
msg = rep.longrepr.reprtraceback.reprentries[-1].reprfileloc
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
msg = tr._getfailureheadline(rep)
|
msg = tr._getfailureheadline(rep)
|
||||||
tw = _pytest.config.create_terminal_writer(
|
file = StringIO()
|
||||||
terminalreporter.config, stringio=True
|
tw = _pytest.config.create_terminal_writer(terminalreporter.config, file)
|
||||||
)
|
|
||||||
rep.toterminal(tw)
|
rep.toterminal(tw)
|
||||||
s = tw.stringio.getvalue()
|
s = file.getvalue()
|
||||||
assert len(s)
|
assert len(s)
|
||||||
pastebinurl = create_new_paste(s)
|
pastebinurl = create_new_paste(s)
|
||||||
tr.write_line("{} --> {}".format(msg, pastebinurl))
|
tr.write_line("{} --> {}".format(msg, pastebinurl))
|
||||||
|
|
|
@ -82,10 +82,11 @@ class BaseReport:
|
||||||
|
|
||||||
.. versionadded:: 3.0
|
.. versionadded:: 3.0
|
||||||
"""
|
"""
|
||||||
tw = TerminalWriter(stringio=True)
|
file = StringIO()
|
||||||
|
tw = TerminalWriter(file)
|
||||||
tw.hasmarkup = False
|
tw.hasmarkup = False
|
||||||
self.toterminal(tw)
|
self.toterminal(tw)
|
||||||
exc = tw.stringio.getvalue()
|
exc = file.getvalue()
|
||||||
return exc.strip()
|
return exc.strip()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import io
|
||||||
import operator
|
import operator
|
||||||
import os
|
import os
|
||||||
import queue
|
import queue
|
||||||
|
@ -1037,10 +1038,11 @@ raise ValueError()
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
excinfo = pytest.raises(ValueError, mod.f)
|
excinfo = pytest.raises(ValueError, mod.f)
|
||||||
tw = TerminalWriter(stringio=True)
|
file = io.StringIO()
|
||||||
|
tw = TerminalWriter(file=file)
|
||||||
repr = excinfo.getrepr(**reproptions)
|
repr = excinfo.getrepr(**reproptions)
|
||||||
repr.toterminal(tw)
|
repr.toterminal(tw)
|
||||||
assert tw.stringio.getvalue()
|
assert file.getvalue()
|
||||||
|
|
||||||
def test_traceback_repr_style(self, importasmod, tw_mock):
|
def test_traceback_repr_style(self, importasmod, tw_mock):
|
||||||
mod = importasmod(
|
mod = importasmod(
|
||||||
|
@ -1255,11 +1257,12 @@ raise ValueError()
|
||||||
getattr(excinfo.value, attr).__traceback__ = None
|
getattr(excinfo.value, attr).__traceback__ = None
|
||||||
|
|
||||||
r = excinfo.getrepr()
|
r = excinfo.getrepr()
|
||||||
tw = TerminalWriter(stringio=True)
|
file = io.StringIO()
|
||||||
|
tw = TerminalWriter(file=file)
|
||||||
tw.hasmarkup = False
|
tw.hasmarkup = False
|
||||||
r.toterminal(tw)
|
r.toterminal(tw)
|
||||||
|
|
||||||
matcher = LineMatcher(tw.stringio.getvalue().splitlines())
|
matcher = LineMatcher(file.getvalue().splitlines())
|
||||||
matcher.fnmatch_lines(
|
matcher.fnmatch_lines(
|
||||||
[
|
[
|
||||||
"ValueError: invalid value",
|
"ValueError: invalid value",
|
||||||
|
|
Loading…
Reference in New Issue