add fixture to capture output in tests less fragile
Now we always remove previous output before capturing.
This commit is contained in:
23
pkgs/clan-cli/tests/stdout.py
Normal file
23
pkgs/clan-cli/tests/stdout.py
Normal file
@@ -0,0 +1,23 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user