test: fix test_schema when the schema validation takes longer#6822
Merged
holmanb merged 1 commit intocanonical:mainfrom Apr 1, 2026
Merged
test: fix test_schema when the schema validation takes longer#6822holmanb merged 1 commit intocanonical:mainfrom
holmanb merged 1 commit intocanonical:mainfrom
Conversation
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 <anisinha@redhat.com>
holmanb
approved these changes
Apr 1, 2026
Member
holmanb
left a comment
There was a problem hiding this comment.
This should help in some circumstances, so this looks good to me. Thanks @ani-sinha.
Comment on lines
+454
to
+455
| assert caplog.record_tuples and ( | ||
| len(caplog.record_tuples) == 1 or len(caplog.record_tuples) == 2 |
Member
There was a problem hiding this comment.
I'm not personally a fan of logging tests for the brittleness which this problem demonstrates.
blackboxsw
pushed a commit
to blackboxsw/cloud-init
that referenced
this pull request
Apr 13, 2026
…cal#6822) 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 test_validateconfig_schema_non_strict_emits_warnings fails. Fix it by checking if the length of the tuple is either one or two, not just one. Signed-off-by: Ani Sinha <anisinha@redhat.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the schema validation takes more than 0.01 seconds, a log is emitted:
Validating schema took 0.070 secondsWhen this happens, the tuple length is 2 and not one and the test fails with the following:
Fix it by checking if the length of the tuple is either one or two, not just one.
Proposed Commit Message
Merge type