Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ convention = "numpy"
[tool.pytest.ini_options]
addopts = ["--doctest-modules"]
asyncio_default_fixture_loop_scope = "function"
filterwarnings = [
# Treat warnings emitted during tests as errors. (This way we can explicitly
# ignore warnings we know to be OK.)
"error",
# Triggered by the fairly old version of protobuf we use
'ignore:_SixMetaPathImporter\.find_spec\(\)\ not\ found;\ falling\ back\ to\ find_module\(\):ImportWarning:importlib._bootstrap'
]

[tool.coverage.run]
omit = [
Expand Down
23 changes: 21 additions & 2 deletions test/test_kv.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,23 @@ def db(create_db: partial[Kv]) -> Kv:
return create_db()


@pytest.fixture
def stopped_loop() -> Generator[asyncio.AbstractEventLoop]:
"""Get an asyncio loop that is not actively running anything."""
try:
loop = asyncio.new_event_loop()
yield loop
assert not loop.is_running()
finally:

async def close() -> None:
await asyncio.wait_for(loop.shutdown_asyncgens(), timeout=0.1)
await asyncio.wait_for(loop.shutdown_default_executor(), timeout=0.1)

loop.run_until_complete(close())
loop.close()


def pack_kv_entry(
key: AnyKvKey, value: bytes, versionstamp: int = 1
) -> ProtobufKvEntry:
Expand Down Expand Up @@ -1020,8 +1037,10 @@ def use_kv_and_finalize() -> None:
assert session.closed


def test_close_via_finalizer__loop_not_running() -> None:
loop = asyncio.new_event_loop()
def test_close_via_finalizer__loop_not_running(
stopped_loop: asyncio.AbstractEventLoop,
) -> None:
loop = stopped_loop
authenticator = Mock()

async def create_session() -> aiohttp.ClientSession:
Expand Down
Loading