Files
clan-core/pkgs/clan-cli/tests/stdout.py
Jörg Thalheim fe66a740b5 add fixture to capture output in tests less fragile
Now we always remove previous output before capturing.
2024-08-15 18:45:03 +02:00

24 lines
567 B
Python

from typing import Any
import pytest
from pytest import CaptureFixture
class CaptureOutput:
def __init__(self, capsys: CaptureFixture) -> None:
self.capsys = capsys
def __enter__(self) -> "CaptureOutput":
self.capsys.readouterr()
return self
def __exit__(self, exc_type: Any, exc_value: Any, exc_traceback: Any) -> bool:
res = self.capsys.readouterr()
self.out = res.out
self.err = res.err
@pytest.fixture
def capture_output(capsys: CaptureFixture) -> CaptureOutput:
return CaptureOutput(capsys)