Skip to content

Commit

Permalink
Decorate async tests with @pytest.mark.asyncio
Browse files Browse the repository at this point in the history
Without this, many tests fail in Python 3.14.0a2 because
`asyncio.get_event_loop()` no longer automatically starts an event loop,
instead raising a `RuntimeError` if there is no current event loop. See
https://docs.python.org/dev/library/asyncio-eventloop.html#asyncio.get_event_loop,
https://docs.python.org/dev/whatsnew/3.14.html#id3, and
python/cpython#126353.
  • Loading branch information
musicinmybrain committed Nov 23, 2024
1 parent 658e71c commit 76c9481
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


class TestService:
@pytest.mark.asyncio
@pytest.mark.parametrize(
('rate_limit', 'period'), ((1, 0.5), (3, 1.0), (100, 1.5))
)
Expand All @@ -19,6 +20,7 @@ async def request(value: float):
main = asyncio.gather(*[request(v) for v in range(int(rate_limit / period) + 100)])
asyncio.get_event_loop().run_until_complete(main)

@pytest.mark.asyncio
@pytest.mark.parametrize(
('max_simultaneous',), ((1,), (3,), (100,))
)
Expand Down
1 change: 1 addition & 0 deletions tests/test_throttler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def test_exceptions(self, rate_limit: int, period: float):
with pytest.raises(ValueError):
Throttler(rate_limit, period)

@pytest.mark.asyncio
@pytest.mark.parametrize(
('rate_limit', 'period', 'count'),
tuple(product((1, 3, 5), (0.5, 1.0, 1.5), (3, 5, 7))) +
Expand Down
1 change: 1 addition & 0 deletions tests/test_throttler_simultaneous.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@


class TestThrottlerSimultaneous:
@pytest.mark.asyncio
@pytest.mark.parametrize(
('max_simultaneous', 'count'), ((1, 10), (3, 10), (100, 500))
)
Expand Down

0 comments on commit 76c9481

Please sign in to comment.