Skip to content

Commit

Permalink
Use the event_loop fixture for tests that need one
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.

For documentation on the fixture, see
https://pytest-asyncio.readthedocs.io/en/latest/reference/fixtures/#event-loop.
  • Loading branch information
musicinmybrain committed Nov 23, 2024
1 parent 658e71c commit 12157cf
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions tests/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TestService:
@pytest.mark.parametrize(
('rate_limit', 'period'), ((1, 0.5), (3, 1.0), (100, 1.5))
)
def test_service(self, rate_limit: int, period: float):
def test_service(self, rate_limit: int, period: float, event_loop):
s = Service(rate_limit, period)

async def request(value: float):
Expand All @@ -22,7 +22,7 @@ async def request(value: float):
@pytest.mark.parametrize(
('max_simultaneous',), ((1,), (3,), (100,))
)
def test_service_simultaneous(self, max_simultaneous: int):
def test_service_simultaneous(self, max_simultaneous: int, event_loop):
s = ServiceSimultaneous(max_simultaneous)

async def request(value: float):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_throttler.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_exceptions(self, rate_limit: int, period: float):
tuple(product((1, 3, 5), (0.5, 1.0, 1.5), (3, 5, 7))) +
tuple(product((100, 1000), (0.5, 1.0, 1.5), (10, 1000)))
)
def test_via_service(self, rate_limit: int, period: float, count: int):
def test_via_service(self, rate_limit: int, period: float, count: int, event_loop):
s = Service(rate_limit, period)

@throttle(rate_limit, period)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_throttler_simultaneous.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class TestThrottlerSimultaneous:
@pytest.mark.parametrize(
('max_simultaneous', 'count'), ((1, 10), (3, 10), (100, 500))
)
def test_via_service_simultaneous(self, max_simultaneous: int, count: int):
def test_via_service_simultaneous(self, max_simultaneous: int, count: int, event_loop):
s = ServiceSimultaneous(max_simultaneous)

@throttle_simultaneous(max_simultaneous)
Expand Down

0 comments on commit 12157cf

Please sign in to comment.