clog/conftest.py
theonepath 6cd0024113
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.
2022-05-12 13:46:11 +01:00

23 lines
506 B
Python

# 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