MCPcopy Create free account
hub / github.com/pytest-dev/pytest / tw_mock

Function tw_mock

testing/conftest.py:68–103  ·  view source on GitHub ↗

Returns a mock terminal writer

()

Source from the content-addressed store, hash-verified

66
67@pytest.fixture
68def tw_mock():
69 """Returns a mock terminal writer"""
70
71 class TWMock:
72 WRITE = object()
73
74 def __init__(self):
75 self.lines = []
76 self.is_writing = False
77
78 def sep(self, sep, line=None):
79 self.lines.append((sep, line))
80
81 def write(self, msg, **kw):
82 self.lines.append((TWMock.WRITE, msg))
83
84 def _write_source(self, lines, indents=()):
85 if not indents:
86 indents = [""] * len(lines)
87 for indent, line in zip(indents, lines):
88 self.line(indent + line)
89
90 def line(self, line, **kw):
91 self.lines.append(line)
92
93 def markup(self, text, **kw):
94 return text
95
96 def get_write_msg(self, idx):
97 flag, msg = self.lines[idx]
98 assert flag == TWMock.WRITE
99 return msg
100
101 fullwidth = 80
102
103 return TWMock()
104
105
106@pytest.fixture

Callers

nothing calls this directly

Calls 1

TWMockClass · 0.85

Tested by

no test coverage detected