MCPcopy Create free account
hub / github.com/hynek/structlog / test_stdout_monkeypatch

Method test_stdout_monkeypatch

tests/test_output.py:175–189  ·  view source on GitHub ↗

If stdout gets monkeypatched, the new instance receives the output.

(self, monkeypatch, capsys)

Source from the content-addressed store, hash-verified

173 assert repr(logger_cls()).startswith(f"<{logger_cls.__name__}(file=")
174
175 def test_stdout_monkeypatch(self, monkeypatch, capsys):
176 """
177 If stdout gets monkeypatched, the new instance receives the output.
178 """
179 import sys
180
181 p = PrintLogger()
182 new_stdout = StringIO()
183 monkeypatch.setattr(sys, "stdout", new_stdout)
184 p.msg("hello")
185
186 out, err = capsys.readouterr()
187 assert "hello\n" == new_stdout.getvalue()
188 assert "" == out
189 assert "" == err
190
191
192class TestPrintLoggerFactory:

Callers

nothing calls this directly

Calls 2

msgMethod · 0.95
PrintLoggerClass · 0.90

Tested by

no test coverage detected