Skip to content

Commit

Permalink
test: Package-scoped event_loop fixture no longer leaks into other te…
Browse files Browse the repository at this point in the history
…sts.

The expected behaviour is that the `event_loop` fixture defined in `tests/sessionloop/conftest.py` is torn down when all tests in `tests/sessionloop` are complete. Running the tests with the pytest option --setup-show pointed out that the fixture is torn down at the end of the test session, instead. This is an unintended side effect of the sessionloop test which may affect other tests in the test suite.

Reducing the fixture scope from "package" to "module" results in the expected behaviour. The module was renamed to reflect the fact that the tests do not use a session scope.

Signed-off-by: Michael Seifert <[email protected]>
  • Loading branch information
seifertm committed Mar 11, 2022
1 parent 82d212b commit aad0316
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import pytest


class CustomSelectorLoopSession(asyncio.SelectorEventLoop):
class CustomSelectorLoop(asyncio.SelectorEventLoop):
"""A subclass with no overrides, just to test for presence."""


loop = CustomSelectorLoopSession()
loop = CustomSelectorLoop()


@pytest.fixture(scope="package")
@pytest.fixture(scope="module")
def event_loop():
"""Create an instance of the default event loop for each test case."""
yield loop
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Unit tests for overriding the event loop with a session scoped one."""
"""Unit tests for overriding the event loop with a larger scoped one."""
import asyncio

import pytest
Expand All @@ -8,7 +8,7 @@
async def test_for_custom_loop():
"""This test should be executed using the custom loop."""
await asyncio.sleep(0.01)
assert type(asyncio.get_event_loop()).__name__ == "CustomSelectorLoopSession"
assert type(asyncio.get_event_loop()).__name__ == "CustomSelectorLoop"


@pytest.mark.asyncio
Expand Down

0 comments on commit aad0316

Please sign in to comment.