From 6cd0024113abc182d27da499bdac2160960bda43 Mon Sep 17 00:00:00 2001 From: theonepath Date: Thu, 12 May 2022 13:46:11 +0100 Subject: [PATCH] Added conftest.py for pytest File contains a fixture which must be present for test_logger module to work functionally. Fixture relates to a monkeypatch implementation for capturing standard PIPEs and storing their results in a buffer. This buffer can then be read after a call to send data on a PIPE stream has been called, via a key lookup on the appropriate stream. --- conftest.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 conftest.py diff --git a/conftest.py b/conftest.py new file mode 100644 index 0000000..d2a13ae --- /dev/null +++ b/conftest.py @@ -0,0 +1,23 @@ +# flake8: noqa +import sys + +import pytest + + +@pytest.fixture +def capture_stdpipe(monkeypatch): + stream_buf = {"stdout": "", "stderr": "", "writes": 0} + + def mimic_stdout(chars): + stream_buf['stdout'] += chars + stream_buf['writes'] += 1 + + def mimic_stderr(chars): + stream_buf['stderr'] += chars + stream_buf['writes'] += 1 + + + monkeypatch.setattr(sys.stdout, 'write', mimic_stdout) + monkeypatch.setattr(sys.stderr, 'write', mimic_stderr) + + return stream_buf \ No newline at end of file