File tree Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Original file line number Diff line number Diff line change 2
2
import pytest
3
3
4
4
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 ):
6
14
dart .common .trace ("trace log" )
7
15
dart .common .debug ("debug log" )
8
16
dart .common .info ("info log" )
9
17
dart .common .warn ("warn log" )
10
18
dart .common .error ("error log" )
11
19
dart .common .fatal ("fatal log" )
12
20
21
+ assert_logged (
22
+ capsys ,
23
+ "trace log" ,
24
+ "debug log" ,
25
+ "info log" ,
26
+ "warn log" ,
27
+ "error log" ,
28
+ "fatal log" ,
29
+ )
13
30
14
- def test_arguments ():
31
+
32
+ def test_arguments (capsys ):
15
33
val = 10
16
34
dart .common .info ("Log with param '{}' and '{}'" .format (1 , val ))
17
35
36
+ assert_logged (capsys , "Log with param '1' and '10'" )
37
+
18
38
19
39
if __name__ == "__main__" :
20
40
pytest .main ()
You can’t perform that action at this time.
0 commit comments