Skip to content

Commit c45f797

Browse files
committed
test: assert logging output
1 parent 49e851b commit c45f797

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

python/tests/unit/common/test_logging.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,39 @@
22
import pytest
33

44

5-
def test_basics():
5+
def assert_logged(capsys, *messages: str) -> None:
6+
"""Read captured logs and ensure *messages* appear in the output."""
7+
captured = capsys.readouterr()
8+
output = captured.out + captured.err
9+
for msg in messages:
10+
assert msg in output, f"{msg!r} not found in captured output"
11+
12+
13+
def test_basics(capsys):
614
dart.common.trace("trace log")
715
dart.common.debug("debug log")
816
dart.common.info("info log")
917
dart.common.warn("warn log")
1018
dart.common.error("error log")
1119
dart.common.fatal("fatal log")
1220

21+
assert_logged(
22+
capsys,
23+
"trace log",
24+
"debug log",
25+
"info log",
26+
"warn log",
27+
"error log",
28+
"fatal log",
29+
)
1330

14-
def test_arguments():
31+
32+
def test_arguments(capsys):
1533
val = 10
1634
dart.common.info("Log with param '{}' and '{}'".format(1, val))
1735

36+
assert_logged(capsys, "Log with param '1' and '10'")
37+
1838

1939
if __name__ == "__main__":
2040
pytest.main()

0 commit comments

Comments
 (0)