config: typing for create_terminal_writer, re-export TerminalWriter
This also imports `TerminalWriter` explicitly via `_pytest._io`, allowing for easier extending / replacing it.
This commit is contained in:
@@ -12,6 +12,7 @@ import pytest
|
||||
from _pytest._code.code import ExceptionChainRepr
|
||||
from _pytest._code.code import ExceptionInfo
|
||||
from _pytest._code.code import FormattedExcinfo
|
||||
from _pytest._io import TerminalWriter
|
||||
|
||||
|
||||
try:
|
||||
@@ -855,7 +856,7 @@ raise ValueError()
|
||||
from _pytest._code.code import TerminalRepr
|
||||
|
||||
class MyRepr(TerminalRepr):
|
||||
def toterminal(self, tw: py.io.TerminalWriter) -> None:
|
||||
def toterminal(self, tw: TerminalWriter) -> None:
|
||||
tw.line("я")
|
||||
|
||||
x = str(MyRepr())
|
||||
@@ -1005,7 +1006,7 @@ raise ValueError()
|
||||
"""
|
||||
)
|
||||
excinfo = pytest.raises(ValueError, mod.f)
|
||||
tw = py.io.TerminalWriter(stringio=True)
|
||||
tw = TerminalWriter(stringio=True)
|
||||
repr = excinfo.getrepr(**reproptions)
|
||||
repr.toterminal(tw)
|
||||
assert tw.stringio.getvalue()
|
||||
@@ -1225,7 +1226,7 @@ raise ValueError()
|
||||
getattr(excinfo.value, attr).__traceback__ = None
|
||||
|
||||
r = excinfo.getrepr()
|
||||
tw = py.io.TerminalWriter(stringio=True)
|
||||
tw = TerminalWriter(stringio=True)
|
||||
tw.hasmarkup = False
|
||||
r.toterminal(tw)
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import logging
|
||||
|
||||
import py.io
|
||||
|
||||
from _pytest._io import TerminalWriter
|
||||
from _pytest.logging import ColoredLevelFormatter
|
||||
|
||||
|
||||
@@ -22,7 +21,7 @@ def test_coloredlogformatter():
|
||||
class option:
|
||||
pass
|
||||
|
||||
tw = py.io.TerminalWriter()
|
||||
tw = TerminalWriter()
|
||||
tw.hasmarkup = True
|
||||
formatter = ColoredLevelFormatter(tw, logfmt)
|
||||
output = formatter.format(record)
|
||||
@@ -142,7 +141,7 @@ def test_colored_short_level():
|
||||
class option:
|
||||
pass
|
||||
|
||||
tw = py.io.TerminalWriter()
|
||||
tw = TerminalWriter()
|
||||
tw.hasmarkup = True
|
||||
formatter = ColoredLevelFormatter(tw, logfmt)
|
||||
output = formatter.format(record)
|
||||
|
||||
Reference in New Issue
Block a user