Run tests with caplog in a single worker (#1304)

This commit is contained in:
Steven B. 2024-11-23 12:20:51 +00:00 committed by GitHub
parent 2bda54fcb1
commit 412c65c428
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 23 additions and 1 deletions

View File

@ -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"]

View File

@ -7,6 +7,7 @@ from ...device_fixtures import device_iot
@device_iot
@pytest.mark.xdist_group(name="caplog")
def test_schedule(dev: Device, caplog: pytest.LogCaptureFixture):
schedule = dev.modules.get(Module.IotSchedule)
assert schedule

View File

@ -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,

View File

@ -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"]

View File

@ -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)

View File

@ -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)

View File

@ -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."""

View File

@ -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,
@ -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"

View File

@ -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
@ -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"

View File

@ -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

View File

@ -184,6 +184,7 @@ async def test_protocol_reconnect(mocker, retry_count, protocol_class, transport
@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)

View File

@ -307,6 +307,7 @@ async def test_protocol_handles_cancellation_during_connection(
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
):
@ -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):

View File

@ -27,6 +27,7 @@ from .conftest import (
@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,
@ -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,
@ -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,

View File

@ -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
):
@ -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
):

View File

@ -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)