Skip to content

Commit

Permalink
Revert upgrade to pytest-asyncio 0.23.2
Browse files Browse the repository at this point in the history
pytest-asyncio 0.23 changed the way event loops work and caused a number
of issues, including pytest-dev/asyncio#705 and
pytest-dev/pytest-asyncio#718. I wasn't able to find an easy way around
these for the qualification test, so for now I've pinned pytest-asyncio
to <0.22 (the 0.22 release was a half-way point to 0.23 and has been
yanked).
  • Loading branch information
bmerry committed Dec 13, 2023
1 parent 18abe67 commit da4a42c
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 20 deletions.
4 changes: 0 additions & 4 deletions qualification/antenna_channelised_voltage/__init__.py
Expand Up @@ -23,17 +23,13 @@
import asyncio

import numpy as np
import pytest
from numpy.typing import ArrayLike

from katgpucbf import DIG_SAMPLE_BITS, N_POLS

from .. import BaselineCorrelationProductsReceiver, CorrelatorRemoteControl
from ..reporter import Reporter

# Make the event_loop package-scoped
pytestmark = pytest.mark.asyncio(scope="package")


async def sample_tone_response_hdr(
correlator: CorrelatorRemoteControl,
Expand Down
5 changes: 0 additions & 5 deletions qualification/baseline_correlation_products/__init__.py
@@ -1,6 +1 @@
# noqa: D104

import pytest

# Make the event_loop package-scoped
pytestmark = pytest.mark.asyncio(scope="package")
8 changes: 8 additions & 0 deletions qualification/conftest.py
Expand Up @@ -171,6 +171,14 @@ def pytest_generate_tests(metafunc: pytest.Metafunc) -> None:
metafunc.parametrize("n_channels, narrowband_decimation", configs, indirect=True)


# Need to redefine this from pytest-asyncio to have it at package scope
@pytest.fixture(scope="package")
def event_loop(): # noqa: D103
loop = asyncio.get_event_loop_policy().new_event_loop()
yield loop
loop.close()


@pytest.fixture(scope="package")
def n_antennas(request: pytest.FixtureRequest): # noqa: D401
"""Number of antennas, i.e. size of the array."""
Expand Down
2 changes: 1 addition & 1 deletion qualification/requirements.txt
Expand Up @@ -265,7 +265,7 @@ pytest==7.4.3
# pytest-check
# pytest-custom-exit-code
# pytest-reportlog
pytest-asyncio==0.23.2
pytest-asyncio==0.21.1
# via
# -c qualification/../requirements-dev.txt
# katgpucbf (setup.cfg)
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Expand Up @@ -275,7 +275,7 @@ pytest==7.4.3
# pytest-custom-exit-code
# pytest-mock
# pytest-xdist
pytest-asyncio==0.23.2
pytest-asyncio==0.21.1
# via katgpucbf (setup.cfg)
pytest-cov==4.1.0
# via -r requirements-dev.in
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Expand Up @@ -49,7 +49,7 @@ test =
async-solipsism
async-timeout
pytest
pytest-asyncio>=0.18
pytest-asyncio>=0.18,<0.22
pytest-custom_exit_code
pytest-mock

Expand Down
13 changes: 5 additions & 8 deletions test/test_utils.py
Expand Up @@ -19,7 +19,7 @@
import asyncio
import gc
import weakref
from typing import AsyncGenerator
from typing import AsyncGenerator, Generator
from unittest import mock

import aiokatcp
Expand All @@ -30,11 +30,6 @@
from katgpucbf.utils import DeviceStatusSensor, TimeConverter, TimeoutSensorStatusObserver


class AsyncSolipsismPolicy(asyncio.DefaultEventLoopPolicy):
def new_event_loop(self) -> async_solipsism.EventLoop:
return async_solipsism.EventLoop()


class TestDeviceStatusSensor:
"""Test :class:`.DeviceStatusSensor`.
Expand Down Expand Up @@ -80,9 +75,11 @@ class TestTimeoutSensorStatus:
"""Tests for :func:`katgpucbf.utils.timeout_sensor_status`."""

@pytest.fixture
def event_loop_policy(self) -> asyncio.AbstractEventLoopPolicy:
def event_loop(self) -> Generator[async_solipsism.EventLoop, None, None]:
"""Use async_solipsism event loop."""
return AsyncSolipsismPolicy()
loop = async_solipsism.EventLoop()
yield loop
loop.close()

@pytest.fixture
def sensor(self) -> aiokatcp.Sensor:
Expand Down

0 comments on commit da4a42c

Please sign in to comment.