Skip to content

Commit

Permalink
Replace per-test pytestmark with a global one in conftest
Browse files Browse the repository at this point in the history
  • Loading branch information
puddly committed Nov 30, 2021
1 parent 2bfe0e2 commit 585aeb7
Show file tree
Hide file tree
Showing 21 changed files with 10 additions and 45 deletions.
2 changes: 0 additions & 2 deletions tests/api/test_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

from ..conftest import BaseServerZNP, CoroutineMock, config_for_port_path

pytestmark = [pytest.mark.asyncio]


async def test_connect_no_test(make_znp_server):
znp_server = make_znp_server(server_cls=BaseServerZNP)
Expand Down
2 changes: 0 additions & 2 deletions tests/api/test_listeners.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import zigpy_znp.commands as c
from zigpy_znp.api import OneShotResponseListener, CallbackResponseListener

pytestmark = [pytest.mark.asyncio]


async def test_resolve(event_loop, mocker):
callback = mocker.Mock()
Expand Down
2 changes: 0 additions & 2 deletions tests/api/test_network_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

from ..conftest import ALL_DEVICES, FORMED_DEVICES, BaseZStack1CC2531

pytestmark = [pytest.mark.asyncio]


@pytest.mark.parametrize("to_device", ALL_DEVICES)
@pytest.mark.parametrize("from_device", FORMED_DEVICES)
Expand Down
2 changes: 0 additions & 2 deletions tests/api/test_nvram.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
from zigpy_znp.types import nvids
from zigpy_znp.exceptions import SecurityError

pytestmark = [pytest.mark.asyncio]


async def test_osal_writes_invalid(connected_znp):
znp, _ = connected_znp
Expand Down
2 changes: 0 additions & 2 deletions tests/api/test_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
from zigpy_znp.frames import GeneralFrame
from zigpy_znp.exceptions import CommandNotRecognized, InvalidCommandResponse

pytestmark = [pytest.mark.asyncio]


async def test_callback_rsp(connected_znp, event_loop):
znp, znp_server = connected_znp
Expand Down
2 changes: 0 additions & 2 deletions tests/api/test_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import zigpy_znp.commands as c
from zigpy_znp.utils import deduplicate_commands

pytestmark = [pytest.mark.asyncio]


async def test_responses(connected_znp):
znp, znp_server = connected_znp
Expand Down
2 changes: 0 additions & 2 deletions tests/application/test_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

from ..conftest import FORMED_DEVICES, FormedLaunchpadCC26X2R1, swap_attribute

pytestmark = [pytest.mark.asyncio]


async def test_no_double_connect(make_znp_server, mocker):
znp_server = make_znp_server(server_cls=FormedLaunchpadCC26X2R1)
Expand Down
2 changes: 0 additions & 2 deletions tests/application/test_joining.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
FormedLaunchpadCC26X2R1,
)

pytestmark = [pytest.mark.asyncio]


@pytest.mark.parametrize(
"device,fixed_joining_bug",
Expand Down
2 changes: 0 additions & 2 deletions tests/application/test_nvram_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

from ..conftest import FORMED_DEVICES, FormedZStack3CC2531

pytestmark = [pytest.mark.asyncio]


@pytest.mark.parametrize("device", FORMED_DEVICES)
async def test_addrmgr_empty_entries(make_connected_znp, device):
Expand Down
2 changes: 0 additions & 2 deletions tests/application/test_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

from ..conftest import FORMED_DEVICES, CoroutineMock, FormedLaunchpadCC26X2R1

pytestmark = [pytest.mark.asyncio]


@pytest.mark.parametrize("device", FORMED_DEVICES)
async def test_zdo_request_interception(device, make_application):
Expand Down
2 changes: 0 additions & 2 deletions tests/application/test_startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
FormedLaunchpadCC26X2R1,
)

pytestmark = [pytest.mark.asyncio]

DEV_NETWORK_SETTINGS = {
FormedLaunchpadCC26X2R1: (
"CC1352/CC2652, Z-Stack 3.30+ (build 20200805)",
Expand Down
2 changes: 0 additions & 2 deletions tests/application/test_zigpy_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

from ..conftest import FORMED_DEVICES, CoroutineMock

pytestmark = [pytest.mark.asyncio]


def awaitable_mock(return_value):
mock_called = asyncio.get_running_loop().create_future()
Expand Down
10 changes: 10 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@
FAKE_SERIAL_PORT = "/dev/ttyFAKE0"


# Globally handle async tests and error on unawaited coroutines
def pytest_collection_modifyitems(session, config, items):
for item in items:
item.add_marker(
pytest.mark.filterwarnings("error::pytest.PytestUnraisableExceptionWarning")
)
item.add_marker(pytest.mark.filterwarnings("error::RuntimeWarning"))
item.add_marker(pytest.mark.asyncio)


class ForwardingSerialTransport:
"""
Serial transport that hooks directly into a protocol
Expand Down
2 changes: 0 additions & 2 deletions tests/test_uart.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ def test_uart_frame_received_error(connected_uart, mocker):
znp.frame_received.call_count == 3


@pytest.mark.asyncio
async def test_connection_lost(dummy_serial_conn, mocker, event_loop):
device, _ = dummy_serial_conn

Expand All @@ -240,7 +239,6 @@ async def test_connection_lost(dummy_serial_conn, mocker, event_loop):
assert (await conn_lost_fut) == exception


@pytest.mark.asyncio
async def test_connection_made(dummy_serial_conn, mocker):
device, _ = dummy_serial_conn
znp = mocker.Mock()
Expand Down
1 change: 0 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def test_command_deduplication_complex():
}


@pytest.mark.asyncio
async def test_combine_concurrent_calls():
class TestFuncs:
def __init__(self):
Expand Down
2 changes: 0 additions & 2 deletions tests/tools/test_energy_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from ..conftest import EMPTY_DEVICES, FORMED_DEVICES


@pytest.mark.asyncio
@pytest.mark.parametrize("device", EMPTY_DEVICES)
async def test_energy_scan_unformed(device, make_znp_server, caplog):
znp_server = make_znp_server(server_cls=device)
Expand All @@ -18,7 +17,6 @@ async def test_energy_scan_unformed(device, make_znp_server, caplog):
assert "Form a network" in caplog.text


@pytest.mark.asyncio
@pytest.mark.parametrize("device", FORMED_DEVICES)
async def test_energy_scan_formed(device, make_znp_server, capsys):
znp_server = make_znp_server(server_cls=device)
Expand Down
3 changes: 0 additions & 3 deletions tests/tools/test_flash.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@

from ..conftest import BaseServerZNP, CoroutineMock

pytestmark = [pytest.mark.asyncio]


random.seed(12345)
FAKE_IMAGE_SIZE = 2 ** 10
FAKE_FLASH = bytearray(
Expand Down
1 change: 0 additions & 1 deletion tests/tools/test_form_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from ..conftest import ALL_DEVICES, EMPTY_DEVICES


@pytest.mark.asyncio
@pytest.mark.parametrize("device", ALL_DEVICES)
async def test_form_network(device, make_znp_server):
znp_server = make_znp_server(server_cls=device)
Expand Down
8 changes: 0 additions & 8 deletions tests/tools/test_network_backup_restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ def test_schema_validation_device_key_info(backup_json):


@pytest.mark.parametrize("device", EMPTY_DEVICES)
@pytest.mark.asyncio
async def test_network_backup_empty(device, make_znp_server):
znp_server = make_znp_server(server_cls=device)

Expand All @@ -144,7 +143,6 @@ async def test_network_backup_empty(device, make_znp_server):


@pytest.mark.parametrize("device", [FormedZStack1CC2531])
@pytest.mark.asyncio
async def test_network_backup_pipe(device, make_znp_server, capsys):
znp_server = make_znp_server(server_cls=device)

Expand All @@ -155,7 +153,6 @@ async def test_network_backup_pipe(device, make_znp_server, capsys):


@pytest.mark.parametrize("device", FORMED_DEVICES)
@pytest.mark.asyncio
async def test_network_backup_formed(device, make_znp_server, tmp_path):
znp_server = make_znp_server(server_cls=device)

Expand Down Expand Up @@ -192,7 +189,6 @@ async def test_network_backup_formed(device, make_znp_server, tmp_path):


@pytest.mark.parametrize("device", ALL_DEVICES)
@pytest.mark.asyncio
async def test_network_restore_and_backup(
device, make_znp_server, backup_json, tmp_path
):
Expand Down Expand Up @@ -230,7 +226,6 @@ async def test_network_restore_and_backup(


@pytest.mark.parametrize("device", [ResetLaunchpadCC26X2R1])
@pytest.mark.asyncio
async def test_network_restore_pick_optimal_tclk(
device, make_znp_server, backup_json, tmp_path
):
Expand All @@ -254,7 +249,6 @@ async def test_network_restore_pick_optimal_tclk(
assert backup_json2["stack_specific"]["zstack"]["tclk_seed"] == old_tclk_seed


@pytest.mark.asyncio
async def test_tc_frame_counter_zstack1(make_connected_znp):
znp, znp_server = await make_connected_znp(BaseZStack1CC2531)
znp_server._nvram[ExNvIds.LEGACY] = {
Expand All @@ -267,7 +261,6 @@ async def test_tc_frame_counter_zstack1(make_connected_znp):
assert (await security.read_tc_frame_counter(znp)) == 0xAABBCCDD


@pytest.mark.asyncio
async def test_tc_frame_counter_zstack30(make_connected_znp):
znp, znp_server = await make_connected_znp(BaseZStack3CC2531)
znp.network_info = BARE_NETWORK_INFO
Expand Down Expand Up @@ -299,7 +292,6 @@ async def test_tc_frame_counter_zstack30(make_connected_znp):
assert (await security.read_tc_frame_counter(znp)) == 0xAABBCCDD


@pytest.mark.asyncio
async def test_tc_frame_counter_zstack33(make_connected_znp):
znp, znp_server = await make_connected_znp(BaseLaunchpadCC26X2R1)
znp.network_info = BARE_NETWORK_INFO
Expand Down
2 changes: 0 additions & 2 deletions tests/tools/test_network_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

from ..conftest import FormedZStack1CC2531, FormedLaunchpadCC26X2R1

pytestmark = [pytest.mark.asyncio]


@pytest.mark.parametrize("device", [FormedLaunchpadCC26X2R1])
async def test_network_scan(device, make_znp_server, capsys):
Expand Down
2 changes: 0 additions & 2 deletions tests/tools/test_nvram.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

from ..conftest import ALL_DEVICES, BaseZStack1CC2531, FormedLaunchpadCC26X2R1

pytestmark = [pytest.mark.asyncio]


def dump_nvram(znp):
obj = {}
Expand Down

0 comments on commit 585aeb7

Please sign in to comment.