Skip to content

Commit

Permalink
unit_tests/test_pubsub: reset PubSub.ID_KEY value
Browse files Browse the repository at this point in the history
Somehow after changing version of `fakeredis`, redis mock stays
the same for all the unit tests even if `mock_pubsub` fixture has the
default scope `function`. That's why value of `PubSub._redis.ID_KEY`
becomes global among all the tests and `pubsub.subscribe` increments
it based on the value from the previous test run.
Fix the issue by resetting `ID_KEY` value to get subscription ID
starting from 1 in `test_subscribe_multiple_channels`.

Signed-off-by: Jeny Sadadia <[email protected]>
  • Loading branch information
Jeny Sadadia authored and gctucker committed Dec 5, 2023
1 parent 6d27983 commit 870415b
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/unit_tests/test_pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ async def test_subscribe_multiple_channels(mock_pubsub):
PubSub._subscriptions dict should have 2 entries. This entries'
keys should be 1, 2, and 3.
"""
# Reset `ID_KEY` value to get subscription ID starting from 1
await mock_pubsub._redis.set(mock_pubsub.ID_KEY, 0)
channels = ((1, 'CHANNEL1'), (2, 'CHANNEL2'), (3, 'CHANNEL3'))
for expected_id, expected_channel in channels:
result = await mock_pubsub.subscribe(expected_channel)
Expand Down

0 comments on commit 870415b

Please sign in to comment.