From a0b0aa131d91079a4449f9fbaadb723d7b37b0ce Mon Sep 17 00:00:00 2001 From: Ani Sinha Date: Tue, 31 Mar 2026 09:58:17 +0530 Subject: [PATCH] test: fix test_schema when the schema validation takes longer When the schema validation takes more than 0.01 seconds, a log is emitted: "Validating schema took 0.070 seconds" When this happens, the tuple length is 2 and not one and the test fails with the following: def test_validateconfig_schema_non_strict_emits_warnings(self, caplog): """When strict is False validate_cloudconfig_schema emits warnings.""" schema = {"properties": {"p1": {"type": "string"}}} validate_cloudconfig_schema({"p1": -1}, schema=schema, strict=False) > assert ( caplog.record_tuples and len(caplog.record_tuples) == 1 ), caplog.record_tuples E AssertionError: [('cloudinit.config.schema', 30, "cloud-config failed schema validation! E p1: -1 is not of type 'string'"), ('cloudinit.performance', 10, 'Validating schema took 0.070 seconds')] Fix it by checking if the length of the tuple is either one or two, not just one. Signed-off-by: Ani Sinha --- tests/unittests/config/test_schema.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unittests/config/test_schema.py b/tests/unittests/config/test_schema.py index 797403bc39f..a3b94eaa98f 100644 --- a/tests/unittests/config/test_schema.py +++ b/tests/unittests/config/test_schema.py @@ -451,8 +451,8 @@ def test_validateconfig_schema_non_strict_emits_warnings(self, caplog): """When strict is False validate_cloudconfig_schema emits warnings.""" schema = {"properties": {"p1": {"type": "string"}}} validate_cloudconfig_schema({"p1": -1}, schema=schema, strict=False) - assert ( - caplog.record_tuples and len(caplog.record_tuples) == 1 + assert caplog.record_tuples and ( + len(caplog.record_tuples) == 1 or len(caplog.record_tuples) == 2 ), caplog.record_tuples [(module, log_level, log_msg)] = caplog.record_tuples assert "cloudinit.config.schema" == module