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(robot-server): replace pytest-aiohttp with pytest-asyncio #10012

Merged
merged 1 commit into from
Apr 20, 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 robot-server/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ robot-server = { editable = true, path = "." }
atomicwrites = { version = "==1.4.0", sys_platform = "== 'win32'" }
colorama = { version = "==0.4.4", sys_platform = "== 'win32'" }
pytest = "~=6.1"
pytest-aiohttp = "==0.3.0"
pytest-asyncio = "~=0.18"
pytest-cov = "==2.10.1"
pytest-xdist = "~=2.2.1 "
requests = "==2.26.0"
Expand Down
363 changes: 31 additions & 332 deletions robot-server/Pipfile.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions robot-server/pytest.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[pytest]
tavern-global-cfg = tests/integration/common.yaml
addopts = --color=yes
asyncio_mode = auto
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


@pytest.fixture
def machine(loop):
def machine():
states = {
"imaginingTable",
"millingLumber",
Expand Down
10 changes: 4 additions & 6 deletions robot-server/tests/service/legacy/routers/test_control.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from asyncio import Event
import asyncio
from mock import call, MagicMock

import pytest
Expand Down Expand Up @@ -216,13 +216,11 @@ def test_identify(api_client, hardware):
[control.post_move_robot, None],
],
)
async def test_concurrent_motion_fails(
hardware, loop, blocking_call, blocking_call_data
):
async def test_concurrent_motion_fails(hardware, blocking_call, blocking_call_data):
"""A test that while a HOME or MOVE is happening, other HOME and MOVE
requests will fail."""

event = Event()
loop = asyncio.get_running_loop()
event = asyncio.Event()

# A wait that will happen within motion lock
async def wait_on_event(*args, **kwargs):
Expand Down
21 changes: 12 additions & 9 deletions robot-server/tests/service/legacy/routers/test_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import pytest
import asyncio
from decoy import matchers
from opentrons.hardware_control import ExecutionManager
from opentrons.hardware_control.modules import (
MagDeck,
Expand All @@ -15,7 +16,7 @@


@pytest.fixture
async def magdeck(loop: asyncio.AbstractEventLoop):
async def magdeck():
usb_port = USBPort(
name="",
hub=None,
Expand All @@ -28,7 +29,7 @@ async def magdeck(loop: asyncio.AbstractEventLoop):
which="magdeck",
simulating=True,
execution_manager=ExecutionManager(),
loop=asyncio.get_event_loop(),
loop=asyncio.get_running_loop(),
)
MagDeck.current_height = PropertyMock(return_value=321)

Expand All @@ -38,7 +39,7 @@ async def magdeck(loop: asyncio.AbstractEventLoop):


@pytest.fixture
async def tempdeck(loop: asyncio.AbstractEventLoop):
async def tempdeck():
usb_port = USBPort(
name="",
hub=None,
Expand All @@ -51,7 +52,7 @@ async def tempdeck(loop: asyncio.AbstractEventLoop):
which="tempdeck",
simulating=True,
execution_manager=ExecutionManager(),
loop=asyncio.get_event_loop(),
loop=asyncio.get_running_loop(),
)
TempDeck.temperature = PropertyMock(return_value=123.0)
TempDeck.target = PropertyMock(return_value=321.0)
Expand All @@ -62,7 +63,7 @@ async def tempdeck(loop: asyncio.AbstractEventLoop):


@pytest.fixture
async def thermocycler(loop: asyncio.AbstractEventLoop):
async def thermocycler():
usb_port = USBPort(
name="",
hub=None,
Expand All @@ -75,7 +76,7 @@ async def thermocycler(loop: asyncio.AbstractEventLoop):
which="thermocycler",
simulating=True,
execution_manager=ExecutionManager(),
loop=loop,
loop=asyncio.get_running_loop(),
)

Thermocycler.lid_status = PropertyMock(return_value="open")
Expand All @@ -95,7 +96,7 @@ async def thermocycler(loop: asyncio.AbstractEventLoop):


@pytest.fixture
async def heater_shaker(loop: asyncio.AbstractEventLoop):
async def heater_shaker():
"""Get a mocked out heater-shaker hardware control object."""
usb_port = USBPort(
name="",
Expand All @@ -109,7 +110,7 @@ async def heater_shaker(loop: asyncio.AbstractEventLoop):
which="heatershaker",
simulating=True,
execution_manager=ExecutionManager(),
loop=loop,
loop=asyncio.get_running_loop(),
)

HeaterShaker.live_data = PropertyMock(
Expand Down Expand Up @@ -290,7 +291,9 @@ def test_post_serial_update(api_client, hardware, tempdeck):
resp = api_client.post("/modules/dummySerialTD/update")

p.assert_called_once_with(
tempdeck, tempdeck._bundled_fw.path, asyncio.get_event_loop()
tempdeck,
tempdeck._bundled_fw.path,
matchers.IsA(asyncio.AbstractEventLoop),
)

body = resp.json()
Expand Down
2 changes: 1 addition & 1 deletion robot-server/tests/service/session/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


@pytest.fixture
async def session(session_manager, loop) -> BaseSession:
async def session(session_manager) -> BaseSession:
"""An added session"""
return await session_manager.add(
session_type=SessionType.live_protocol, session_meta_data=SessionMetaData()
Expand Down