Skip to content

[4/8] Use assert(Not)Regex instead of assertTrue or assertFalse in tests - #5243

Merged
akesandgren merged 2 commits into
easybuilders:developfrom
Flamefire:assertregex-4
Sep 16, 2026
Merged

akesandgren merged 2 commits into
easybuilders:developfrom
Flamefire:assertregex-4

Conversation

@Flamefire

Copy link
Copy Markdown
Contributor

This makes the tests shorter and hence easier to read, avoids re.compile calls and manual failure message composing. In some cases assert_multi_regex could be used to avoid the explicit loops.

@Flamefire

Copy link
Copy Markdown
Contributor Author

@boegel I just had to fix a test:
self.assert_multi_regex automatically considers the passed patterns as multi-line enabled. But the test intended to check for whitespace at the beginning and end of the whole string only.

This begs the question if the default of multi_line=True is correct: It works (now) for all checks, most are simple patterns not affected by that setting anyway. But it seems the better default would be False matching the semantics of assert(Not)Regex
But I simply copied the existing _assert_regexs function from test/framework/options.py which had this default.

@boegel boegel added the tests label Sep 4, 2026
@Flamefire
Flamefire force-pushed the assertregex-4 branch 4 times, most recently from 4b51e65 to 5396fa3 Compare September 15, 2026 12:58
… in tests

This makes the tests shorter and hence easier to read, avoids
`re.compile` calls and manual failure message composing.
In some cases `assert_multi_regex` could be used to avoid the explicit loops.

@akesandgren akesandgren left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@akesandgren akesandgren added this to the next release (5.4.1) milestone Sep 16, 2026
@akesandgren

Copy link
Copy Markdown
Contributor

Going in, thanks @Flamefire!

@akesandgren
akesandgren merged commit 3c70f28 into easybuilders:develop Sep 16, 2026
41 checks passed
@Flamefire
Flamefire deleted the assertregex-4 branch September 16, 2026 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants