@@ -15,7 +15,7 @@ async def test_actor_logs_messages_correctly(caplog: pytest.LogCaptureFixture) -
1515 caplog .set_level (logging .DEBUG , logger = 'apify' )
1616
1717 with contextlib .suppress (RuntimeError ):
18- async with Actor (configure_logging = False ):
18+ async with Actor (configure_logging = False , exit_process = False ):
1919 # Test Actor.log
2020 Actor .log .debug ('Debug message' )
2121 Actor .log .info ('Info message' )
@@ -36,77 +36,72 @@ async def test_actor_logs_messages_correctly(caplog: pytest.LogCaptureFixture) -
3636 # Test that exception in Actor.main is logged with the traceback
3737 raise RuntimeError ('Dummy RuntimeError' )
3838
39+ # We skip the first entry, as it is related to the initialization of `lazy_object_proxy.Proxy` for `Actor`.
40+ records = caplog .records [1 :]
41+
3942 # Updated expected number of log records (additional debug messages added)
40- assert len (caplog .records ) == 16
41-
42- # Record 0: First Pytest context log
43- assert caplog .records [0 ].levelno == logging .DEBUG
44- assert caplog .records [0 ].message .startswith ('Running in Pytest' )
45-
46- # Record 1: Duplicate Pytest context log
47- assert caplog .records [1 ].levelno == logging .DEBUG
48- assert caplog .records [1 ].message .startswith ('Running in Pytest' )
49-
50- # Record 2: Logging configured
51- assert caplog .records [2 ].levelno == logging .DEBUG
52- assert caplog .records [2 ].message == 'Logging configured'
53-
54- # Record 3: Initializing Actor
55- assert caplog .records [3 ].levelno == logging .INFO
56- assert caplog .records [3 ].message == 'Initializing Actor'
57-
58- # Record 4: Configuration initialized
59- assert caplog .records [4 ].levelno == logging .DEBUG
60- assert caplog .records [4 ].message == 'Configuration initialized'
61-
62- # Record 5: Storage client initialized
63- assert caplog .records [5 ].levelno == logging .DEBUG
64- assert caplog .records [5 ].message == 'Storage client initialized'
65-
66- # Record 6: Event manager initialized
67- assert caplog .records [6 ].levelno == logging .DEBUG
68- assert caplog .records [6 ].message == 'Event manager initialized'
69-
70- # Record 7: Charging manager initialized
71- assert caplog .records [7 ].levelno == logging .DEBUG
72- assert caplog .records [7 ].message == 'Charging manager initialized'
73-
74- # Record 8: Debug message
75- assert caplog .records [8 ].levelno == logging .DEBUG
76- assert caplog .records [8 ].message == 'Debug message'
77-
78- # Record 9: Info message
79- assert caplog .records [9 ].levelno == logging .INFO
80- assert caplog .records [9 ].message == 'Info message'
81-
82- # Record 10: Warning message
83- assert caplog .records [10 ].levelno == logging .WARNING
84- assert caplog .records [10 ].message == 'Warning message'
85-
86- # Record 11: Error message
87- assert caplog .records [11 ].levelno == logging .ERROR
88- assert caplog .records [11 ].message == 'Error message'
89-
90- # Record 12: Exception message with traceback (ValueError)
91- assert caplog .records [12 ].levelno == logging .ERROR
92- assert caplog .records [12 ].message == 'Exception message'
93- assert caplog .records [12 ].exc_info is not None
94- assert caplog .records [12 ].exc_info [0 ] is ValueError
95- assert isinstance (caplog .records [12 ].exc_info [1 ], ValueError )
96- assert str (caplog .records [12 ].exc_info [1 ]) == 'Dummy ValueError'
97-
98- # Record 13: Multiline log message
99- assert caplog .records [13 ].levelno == logging .INFO
100- assert caplog .records [13 ].message == 'Multi\n line\n log\n message'
101-
102- # Record 14: Actor failed with an exception (RuntimeError)
103- assert caplog .records [14 ].levelno == logging .ERROR
104- assert caplog .records [14 ].message == 'Actor failed with an exception'
105- assert caplog .records [14 ].exc_info is not None
106- assert caplog .records [14 ].exc_info [0 ] is RuntimeError
107- assert isinstance (caplog .records [14 ].exc_info [1 ], RuntimeError )
108- assert str (caplog .records [14 ].exc_info [1 ]) == 'Dummy RuntimeError'
109-
110- # Record 15: Exiting Actor
111- assert caplog .records [15 ].levelno == logging .INFO
112- assert caplog .records [15 ].message == 'Exiting Actor'
43+ assert len (records ) == 14
44+
45+ # Record 0: Logging configured
46+ assert records [0 ].levelno == logging .DEBUG
47+ assert records [0 ].message == 'Logging configured'
48+
49+ # Record 1: Initializing Actor
50+ assert records [1 ].levelno == logging .INFO
51+ assert records [1 ].message == 'Initializing Actor'
52+
53+ # Record 2: Configuration initialized
54+ assert records [2 ].levelno == logging .DEBUG
55+ assert records [2 ].message == 'Configuration initialized'
56+
57+ # Record 3: Storage client initialized
58+ assert records [3 ].levelno == logging .DEBUG
59+ assert records [3 ].message == 'Storage client initialized'
60+
61+ # Record 4: Event manager initialized
62+ assert records [4 ].levelno == logging .DEBUG
63+ assert records [4 ].message == 'Event manager initialized'
64+
65+ # Record 5: Charging manager initialized
66+ assert records [5 ].levelno == logging .DEBUG
67+ assert records [5 ].message == 'Charging manager initialized'
68+
69+ # Record 6: Debug message
70+ assert records [6 ].levelno == logging .DEBUG
71+ assert records [6 ].message == 'Debug message'
72+
73+ # Record 7: Info message
74+ assert records [7 ].levelno == logging .INFO
75+ assert records [7 ].message == 'Info message'
76+
77+ # Record 8: Warning message
78+ assert records [8 ].levelno == logging .WARNING
79+ assert records [8 ].message == 'Warning message'
80+
81+ # Record 9: Error message
82+ assert records [9 ].levelno == logging .ERROR
83+ assert records [9 ].message == 'Error message'
84+
85+ # Record 10: Exception message with traceback (ValueError)
86+ assert records [10 ].levelno == logging .ERROR
87+ assert records [10 ].message == 'Exception message'
88+ assert records [10 ].exc_info is not None
89+ assert records [10 ].exc_info [0 ] is ValueError
90+ assert isinstance (records [10 ].exc_info [1 ], ValueError )
91+ assert str (records [10 ].exc_info [1 ]) == 'Dummy ValueError'
92+
93+ # Record 11: Multiline log message
94+ assert records [11 ].levelno == logging .INFO
95+ assert records [11 ].message == 'Multi\n line\n log\n message'
96+
97+ # Record 12: Actor failed with an exception (RuntimeError)
98+ assert records [12 ].levelno == logging .ERROR
99+ assert records [12 ].message == 'Actor failed with an exception'
100+ assert records [12 ].exc_info is not None
101+ assert records [12 ].exc_info [0 ] is RuntimeError
102+ assert isinstance (records [12 ].exc_info [1 ], RuntimeError )
103+ assert str (records [12 ].exc_info [1 ]) == 'Dummy RuntimeError'
104+
105+ # Record 13: Exiting Actor
106+ assert records [13 ].levelno == logging .INFO
107+ assert records [13 ].message == 'Exiting Actor'
0 commit comments