If stdout gets monkeypatched, the new instance receives the output.
(self, monkeypatch, capsys)
| 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 | |
| 192 | class TestPrintLoggerFactory: |
nothing calls this directly
no test coverage detected