Skip to content

Run tests with caplog in a single worker #1304

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

Merged
merged 4 commits into from
Nov 23, 2024
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
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ markers = [
asyncio_mode = "auto"
asyncio_default_fixture_loop_scope = "function"
timeout = 10
addopts = "--disable-socket --allow-unix-socket"
# dist=loadgroup enables grouping of tests into single worker.
# required as caplog doesn't play nicely with multiple workers.
addopts = "--disable-socket --allow-unix-socket --dist=loadgroup"

[tool.doc8]
paths = ["docs"]
Expand Down
1 change: 1 addition & 0 deletions tests/iot/modules/test_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@


@device_iot
@pytest.mark.xdist_group(name="caplog")
def test_schedule(dev: Device, caplog: pytest.LogCaptureFixture):
schedule = dev.modules.get(Module.IotSchedule)
assert schedule
Expand Down
1 change: 1 addition & 0 deletions tests/smart/modules/test_firmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ async def test_update_available_without_cloud(dev: SmartDevice):
],
)
@pytest.mark.requires_dummy
@pytest.mark.xdist_group(name="caplog")
async def test_firmware_update(
dev: SmartDevice,
mocker: MockerFixture,
Expand Down
1 change: 1 addition & 0 deletions tests/smart/modules/test_temperaturecontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ async def test_thermostat_mode(dev, mode, states, frost_protection):
),
],
)
@pytest.mark.xdist_group(name="caplog")
async def test_thermostat_mode_warnings(dev, mode, states, msg, caplog):
"""Test thermostat modes that should log a warning."""
temp_module: TemperatureControl = dev.modules["TemperatureControl"]
Expand Down
1 change: 1 addition & 0 deletions tests/test_aestransport.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ async def test_send(mocker, status_code, error_code, inner_error_code, expectati
assert "result" in res


@pytest.mark.xdist_group(name="caplog")
async def test_unencrypted_response(mocker, caplog):
host = "127.0.0.1"
mock_aes_device = MockAesDevice(host, 200, 0, 0, do_not_encrypt_response=True)
Expand Down
1 change: 1 addition & 0 deletions tests/test_bulb.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ async def test_set_color_temp_transition(dev: IotBulb, mocker):


@variable_temp_iot
@pytest.mark.xdist_group(name="caplog")
async def test_unknown_temp_range(dev: IotBulb, monkeypatch, caplog):
monkeypatch.setitem(dev._sys_info, "model", "unknown bulb")
light = dev.modules.get(Module.Light)
Expand Down
1 change: 1 addition & 0 deletions tests/test_childdevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ async def test_child_time(dev: Device, freezer: FrozenDateTimeFactory):
assert child.time != fallback_time


@pytest.mark.xdist_group(name="caplog")
async def test_child_device_type_unknown(caplog):
"""Test for device type when category is unknown."""

Expand Down
2 changes: 2 additions & 0 deletions tests/test_device_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ async def test_connect_custom_port(discovery_mock, mocker, custom_port):
assert dev.port == custom_port or dev.port == default_port


@pytest.mark.xdist_group(name="caplog")
async def test_connect_logs_connect_time(
discovery_mock,
caplog: pytest.LogCaptureFixture,
Expand Down Expand Up @@ -192,6 +193,7 @@ async def test_device_types(dev: Device):
assert dev.device_type == res


@pytest.mark.xdist_group(name="caplog")
async def test_device_class_from_unknown_family(caplog):
"""Verify that unknown SMART devices yield a warning and fallback to SmartDevice."""
dummy_name = "SMART.foo"
Expand Down
2 changes: 2 additions & 0 deletions tests/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ async def test_type_detection_lightstrip(dev: Device):
assert d.device_type == DeviceType.LightStrip


@pytest.mark.xdist_group(name="caplog")
async def test_type_unknown(caplog):
invalid_info = {"system": {"get_sysinfo": {"type": "nosuchtype"}}}
assert Discover._get_device_class(invalid_info) is IotPlug
Expand Down Expand Up @@ -586,6 +587,7 @@ async def test_do_discover_external_cancel(mocker):
await dp.wait_for_discovery_to_complete()


@pytest.mark.xdist_group(name="caplog")
async def test_discovery_redaction(discovery_mock, caplog: pytest.LogCaptureFixture):
"""Test query sensitive info redaction."""
mac = "12:34:56:78:9A:BC"
Expand Down
1 change: 1 addition & 0 deletions tests/test_feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ async def test_feature_action(mocker):
mock_call_action.assert_called()


@pytest.mark.xdist_group(name="caplog")
async def test_feature_choice_list(dummy_feature, caplog, mocker: MockerFixture):
"""Test the choice feature type."""
dummy_feature.type = Feature.Type.Choice
Expand Down
1 change: 1 addition & 0 deletions tests/test_klapprotocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ def _fail_one_less_than_retry_count(*_, **__):


@pytest.mark.parametrize("log_level", [logging.WARNING, logging.DEBUG])
@pytest.mark.xdist_group(name="caplog")
async def test_protocol_logging(mocker, caplog, log_level):
caplog.set_level(log_level)
logging.getLogger("kasa").setLevel(log_level)
Expand Down
2 changes: 2 additions & 0 deletions tests/test_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ def aio_mock_writer(_, __):
ids=("_deprecated_TPLinkSmartHomeProtocol", "IotProtocol-XorTransport"),
)
@pytest.mark.parametrize("log_level", [logging.WARNING, logging.DEBUG])
@pytest.mark.xdist_group(name="caplog")
async def test_protocol_logging(
mocker, caplog, log_level, protocol_class, transport_class, encryption_class
):
Expand Down Expand Up @@ -685,6 +686,7 @@ def test_deprecated_protocol():


@device_iot
@pytest.mark.xdist_group(name="caplog")
async def test_iot_queries_redaction(dev: IotDevice, caplog: pytest.LogCaptureFixture):
"""Test query sensitive info redaction."""
if isinstance(dev.protocol._transport, FakeIotTransport):
Expand Down
3 changes: 3 additions & 0 deletions tests/test_smartdevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

@device_smart
@pytest.mark.requires_dummy
@pytest.mark.xdist_group(name="caplog")
async def test_try_get_response(dev: SmartDevice, caplog):
mock_response: dict = {
"get_device_info": SmartErrorCode.PARAMS_ERROR,
Expand Down Expand Up @@ -143,6 +144,7 @@ async def test_update_module_queries(dev: SmartDevice, mocker: MockerFixture):


@device_smart
@pytest.mark.xdist_group(name="caplog")
async def test_update_module_update_delays(
dev: SmartDevice,
mocker: MockerFixture,
Expand Down Expand Up @@ -203,6 +205,7 @@ async def test_update_module_update_delays(
],
)
@device_smart
@pytest.mark.xdist_group(name="caplog")
async def test_update_module_query_errors(
dev: SmartDevice,
mocker: MockerFixture,
Expand Down
2 changes: 2 additions & 0 deletions tests/test_smartprotocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ async def test_smart_device_errors(dummy_protocol, mocker, error_code):


@pytest.mark.parametrize("error_code", [-13333, 13333])
@pytest.mark.xdist_group(name="caplog")
async def test_smart_device_unknown_errors(
dummy_protocol, mocker, error_code, caplog: pytest.LogCaptureFixture
):
Expand Down Expand Up @@ -417,6 +418,7 @@ async def test_incomplete_list(mocker, caplog):


@device_smart
@pytest.mark.xdist_group(name="caplog")
async def test_smart_queries_redaction(
dev: SmartDevice, caplog: pytest.LogCaptureFixture
):
Expand Down
1 change: 1 addition & 0 deletions tests/test_sslaestransport.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ async def test_send(mocker):
assert "result" in res


@pytest.mark.xdist_group(name="caplog")
async def test_unencrypted_response(mocker, caplog):
host = "127.0.0.1"
mock_ssl_aes_device = MockSslAesDevice(host, do_not_encrypt_response=True)
Expand Down
Loading