Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(hardware): replace pytest-aiohttp with pytest-asyncio #10022

Merged
merged 5 commits into from
Apr 21, 2022
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
2 changes: 1 addition & 1 deletion hardware/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ pydantic = "==1.8.2"
[dev-packages]
pytest = "==6.1.0"
pytest-lazy-fixture = "==0.6.3"
pytest-aiohttp = "==0.3.0"
pytest-cov = "==2.10.1"
mypy = "==0.910"
black = "==22.3.0"
Expand All @@ -24,6 +23,7 @@ flake8-noqa = "~=1.2.1"
mock = "~=4.0.2"
types-mock = "==4.0.1"
hypothesis = "~=6.36.1"
pytest-asyncio = "~=0.18"

[requires]
python_version = "3.7"
371 changes: 23 additions & 348 deletions hardware/Pipfile.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion hardware/pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ addopts = --color=yes
markers =
slow: mark test as slow
requires_emulator: mark test as requiring emulator
can_filter_func: can message filtering function
can_filter_func: can message filtering function
asyncio_mode = auto
5 changes: 1 addition & 4 deletions hardware/tests/firmware_integration/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Common fixtures for integration tests."""
from __future__ import annotations
import pytest
import asyncio
from typing import AsyncGenerator, Iterator, AsyncIterator, List, Dict

from _pytest.fixtures import FixtureRequest
Expand All @@ -14,9 +13,7 @@


@pytest.fixture
async def driver(
loop: asyncio.BaseEventLoop,
) -> AsyncGenerator[AbstractCanDriver, None]:
async def driver() -> AsyncGenerator[AbstractCanDriver, None]:
"""Create CanDriver connected to OT-3 Emulator."""
settings = DriverSettings()
driver = await build_driver(settings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def filter_func(arb: ArbitrationId) -> bool:
@pytest.mark.requires_emulator
@pytest.mark.can_filter_func.with_args(filter_func)
async def test_attached_tools_request(
loop: asyncio.BaseEventLoop,
can_messenger: CanMessenger,
can_messenger_queue: WaitableCallback,
) -> None:
Expand Down
4 changes: 1 addition & 3 deletions hardware/tests/firmware_integration/test_device_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def filter_func(arb: ArbitrationId) -> bool:
@pytest.mark.requires_emulator
@pytest.mark.can_filter_func.with_args(filter_func)
async def test_broadcast(
loop: asyncio.BaseEventLoop,
can_messenger: CanMessenger,
can_messenger_queue: WaitableCallback,
) -> None:
Expand All @@ -44,14 +43,13 @@ async def _check() -> None:
if arbitration_id.parts.originating_node_id in nodes:
nodes.remove(arbitration_id.parts.originating_node_id)

t = loop.create_task(_check())
t = asyncio.get_running_loop().create_task(_check())
await asyncio.wait_for(t, 1)


@pytest.mark.requires_emulator
@pytest.mark.can_filter_func.with_args(filter_func)
async def test_each_node(
loop: asyncio.BaseEventLoop,
can_messenger: CanMessenger,
can_messenger_queue: WaitableCallback,
subsystem_node_id: NodeId,
Expand Down
1 change: 0 additions & 1 deletion hardware/tests/firmware_integration/test_eeprom.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def filter_func(arb: ArbitrationId) -> bool:
@pytest.mark.requires_emulator
@pytest.mark.can_filter_func.with_args(filter_func)
async def test_read_write(
loop: asyncio.BaseEventLoop,
can_messenger: CanMessenger,
can_messenger_queue: WaitableCallback,
) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def filter_func(arb: ArbitrationId) -> bool:
@pytest.mark.requires_emulator
@pytest.mark.can_filter_func.with_args(filter_func)
async def test_each_node(
loop: asyncio.BaseEventLoop,
can_messenger: CanMessenger,
can_messenger_queue: WaitableCallback,
motor_node_id: NodeId,
Expand Down
1 change: 0 additions & 1 deletion hardware/tests/firmware_integration/test_motor_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def filter_func(arb: ArbitrationId) -> bool:
@pytest.mark.requires_emulator
@pytest.mark.can_filter_func.with_args(filter_func)
async def test_read_write(
loop: asyncio.BaseEventLoop,
can_messenger: CanMessenger,
can_messenger_queue: WaitableCallback,
motor_node_id: NodeId,
Expand Down
2 changes: 0 additions & 2 deletions hardware/tests/firmware_integration/test_move_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def filter_func(arb: ArbitrationId) -> bool:
@pytest.mark.requires_emulator
@pytest.mark.can_filter_func.with_args(filter_func)
async def test_add_moves(
loop: asyncio.BaseEventLoop,
can_messenger: CanMessenger,
can_messenger_queue: WaitableCallback,
motor_node_id: NodeId,
Expand Down Expand Up @@ -87,7 +86,6 @@ async def test_add_moves(

@pytest.mark.requires_emulator
async def test_move_integration(
loop: asyncio.BaseEventLoop,
can_messenger: CanMessenger,
can_messenger_queue: WaitableCallback,
all_motor_nodes: List[NodeId],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@


@pytest.fixture
async def incoming_messages(loop: asyncio.AbstractEventLoop) -> Queue[CanMessage]:
async def incoming_messages() -> Queue[CanMessage]:
"""Incoming message queue."""
return asyncio.Queue()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Can Driver tests."""
import asyncio
from typing import AsyncGenerator

import pytest
Expand All @@ -24,9 +23,7 @@ def can_bus(bus_channel: str) -> Bus:


@pytest.fixture
async def subject(
loop: asyncio.BaseEventLoop, bus_channel: str
) -> AsyncGenerator[CanDriver, None]:
async def subject(bus_channel: str) -> AsyncGenerator[CanDriver, None]:
"""The can driver under test."""
driver = await CanDriver.build(channel=bus_channel, interface="virtual", bitrate=0)
yield driver
Expand Down