Skip to content

Commit 7f94d8d

Browse files
authored
Correctly exit actors in unit tests (#47)
We had a small bug in the unit tests that some actors were not exited cleanly, so their event-emitting intervals were still running, and pytest was showing a warning about an async task being destroyed but still pending. This fixes it.
1 parent 6eb1630 commit 7f94d8d

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

tests/unit/actor/test_actor_env_helpers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,5 @@ async def test_get_env_use_env_vars(self, monkeypatch: pytest.MonkeyPatch) -> No
4848

4949
await Actor.init()
5050
assert expected_get_env == Actor.get_env()
51+
52+
await Actor.exit()

tests/unit/actor/test_actor_lifecycle.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ async def actor_function() -> None:
127127
# NOTE: Actor didn't call sys.exit() during testing, check if fail was called.
128128
my_actor.fail.assert_called_with(exit_code=91, _exc_type=type(err), _exc_value=err, _exc_traceback=err.__traceback__)
129129

130+
# This is necessary to stop the event emitting intervals
131+
await my_actor.exit()
132+
130133
async def test_actor_main_method_raise_return_value(self) -> None:
131134
my_actor = Actor()
132135
expected_string = 'Hello world'

0 commit comments

Comments
 (0)