Skip to content

Commit 1cc80bb

Browse files
committed
Update log test
1 parent 506b770 commit 1cc80bb

File tree

2 files changed

+36
-32
lines changed

2 files changed

+36
-32
lines changed

src/apify/_actor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ async def init(self) -> None:
288288
This method should be called immediately before performing any additional Actor actions, and it should be
289289
called only once.
290290
"""
291+
self.log.info('Initializing Actor...')
291292
if self._configuration:
292293
# Set explicitly the configuration in the service locator
293294
service_locator.set_configuration(self.configuration)
@@ -315,7 +316,6 @@ async def init(self) -> None:
315316
if self._configure_logging:
316317
_configure_logging()
317318

318-
self.log.info('Initializing Actor...')
319319
self.log.info('System info', extra=get_system_info())
320320

321321
await self.event_manager.__aenter__()

tests/unit/actor/test_actor_log.py

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ async def test_actor_logs_messages_correctly(caplog: pytest.LogCaptureFixture) -
3737
raise RuntimeError('Dummy RuntimeError')
3838

3939
# Updated expected number of log records (an extra record is now captured)
40-
assert len(caplog.records) == 14
40+
assert len(caplog.records) == 15
4141

4242
# Record 0: Extra Pytest context log
4343
assert caplog.records[0].levelno == logging.DEBUG
@@ -51,54 +51,58 @@ async def test_actor_logs_messages_correctly(caplog: pytest.LogCaptureFixture) -
5151
assert caplog.records[2].levelno == logging.INFO
5252
assert caplog.records[2].message == 'Initializing Actor...'
5353

54+
# Record 2: Initializing Actor...
55+
assert caplog.records[3].levelno == logging.DEBUG
56+
assert caplog.records[3].message.startswith('Storage client set to')
57+
5458
# Record 3: System info
55-
assert caplog.records[3].levelno == logging.INFO
56-
assert caplog.records[3].message == 'System info'
59+
assert caplog.records[4].levelno == logging.INFO
60+
assert caplog.records[4].message == 'System info'
5761

5862
# Record 4: Event manager initialized
59-
assert caplog.records[4].levelno == logging.DEBUG
60-
assert caplog.records[4].message == 'Event manager initialized'
63+
assert caplog.records[5].levelno == logging.DEBUG
64+
assert caplog.records[5].message == 'Event manager initialized'
6165

6266
# Record 5: Charging manager initialized
63-
assert caplog.records[5].levelno == logging.DEBUG
64-
assert caplog.records[5].message == 'Charging manager initialized'
67+
assert caplog.records[6].levelno == logging.DEBUG
68+
assert caplog.records[6].message == 'Charging manager initialized'
6569

6670
# Record 6: Debug message
67-
assert caplog.records[6].levelno == logging.DEBUG
68-
assert caplog.records[6].message == 'Debug message'
71+
assert caplog.records[7].levelno == logging.DEBUG
72+
assert caplog.records[7].message == 'Debug message'
6973

7074
# Record 7: Info message
71-
assert caplog.records[7].levelno == logging.INFO
72-
assert caplog.records[7].message == 'Info message'
75+
assert caplog.records[8].levelno == logging.INFO
76+
assert caplog.records[8].message == 'Info message'
7377

7478
# Record 8: Warning message
75-
assert caplog.records[8].levelno == logging.WARNING
76-
assert caplog.records[8].message == 'Warning message'
79+
assert caplog.records[9].levelno == logging.WARNING
80+
assert caplog.records[9].message == 'Warning message'
7781

7882
# Record 9: Error message
79-
assert caplog.records[9].levelno == logging.ERROR
80-
assert caplog.records[9].message == 'Error message'
83+
assert caplog.records[10].levelno == logging.ERROR
84+
assert caplog.records[10].message == 'Error message'
8185

8286
# Record 10: Exception message with traceback (ValueError)
83-
assert caplog.records[10].levelno == logging.ERROR
84-
assert caplog.records[10].message == 'Exception message'
85-
assert caplog.records[10].exc_info is not None
86-
assert caplog.records[10].exc_info[0] is ValueError
87-
assert isinstance(caplog.records[10].exc_info[1], ValueError)
88-
assert str(caplog.records[10].exc_info[1]) == 'Dummy ValueError'
87+
assert caplog.records[11].levelno == logging.ERROR
88+
assert caplog.records[11].message == 'Exception message'
89+
assert caplog.records[11].exc_info is not None
90+
assert caplog.records[11].exc_info[0] is ValueError
91+
assert isinstance(caplog.records[11].exc_info[1], ValueError)
92+
assert str(caplog.records[11].exc_info[1]) == 'Dummy ValueError'
8993

9094
# Record 11: Multiline log message
91-
assert caplog.records[11].levelno == logging.INFO
92-
assert caplog.records[11].message == 'Multi\nline\nlog\nmessage'
95+
assert caplog.records[12].levelno == logging.INFO
96+
assert caplog.records[12].message == 'Multi\nline\nlog\nmessage'
9397

9498
# Record 12: Actor failed with an exception (RuntimeError)
95-
assert caplog.records[12].levelno == logging.ERROR
96-
assert caplog.records[12].message == 'Actor failed with an exception'
97-
assert caplog.records[12].exc_info is not None
98-
assert caplog.records[12].exc_info[0] is RuntimeError
99-
assert isinstance(caplog.records[12].exc_info[1], RuntimeError)
100-
assert str(caplog.records[12].exc_info[1]) == 'Dummy RuntimeError'
99+
assert caplog.records[13].levelno == logging.ERROR
100+
assert caplog.records[13].message == 'Actor failed with an exception'
101+
assert caplog.records[13].exc_info is not None
102+
assert caplog.records[13].exc_info[0] is RuntimeError
103+
assert isinstance(caplog.records[13].exc_info[1], RuntimeError)
104+
assert str(caplog.records[13].exc_info[1]) == 'Dummy RuntimeError'
101105

102106
# Record 13: Exiting Actor
103-
assert caplog.records[13].levelno == logging.INFO
104-
assert caplog.records[13].message == 'Exiting Actor'
107+
assert caplog.records[14].levelno == logging.INFO
108+
assert caplog.records[14].message == 'Exiting Actor'

0 commit comments

Comments
 (0)