Set default values on TraceTestCase to avoid errors on >=8.2.0 pytest#236
Merged
claraberendsen merged 5 commits intoFeb 26, 2026
Merged
Conversation
7 tasks
--- In pytest >=8.2.0 the unittest logic has been reworked to work more like a Function/Class, (see pytest-dev/pytest/pull/12089). This has the side-effect that during the collection phase all test are instantiated and given that the __init__ func of TraceTestCase includes required keyword arguments not being fulfilled in the collection phase it errors. This is avoided by setting default values on the __init__ definition so a `TraceTestCase.__init__() ` run during collection phase won't error. pytest changelog: https://docs.pytest.org/en/stable/changelog.html#pytest-8-2-0-2024-04-27 Signed-off-by: claraberendsen <42071084+claraberendsen@users.noreply.github.com>
8f8dd67 to
8b630dc
Compare
Signed-off-by: claraberendsen <42071084+claraberendsen@users.noreply.github.com>
8b630dc to
af7b648
Compare
Signed-off-by: claraberendsen <42071084+claraberendsen@users.noreply.github.com>
christophebedard
approved these changes
Feb 26, 2026
Member
christophebedard
left a comment
There was a problem hiding this comment.
Seems OK to me with green CI if this doesn't affect the actual tests in any way (i.e., the value of these constructor arguments).
Co-authored-by: Christophe Bedard <bedard.christophe@gmail.com> Signed-off-by: Clara Berendsen <42071084+claraberendsen@users.noreply.github.com>
9c5c046 to
36f54aa
Compare
Signed-off-by: claraberendsen <42071084+claraberendsen@users.noreply.github.com>
Contributor
Author
|
Pulls: #236 |
RaphvK
pushed a commit
to RaphvK/ros2_tracing
that referenced
this pull request
Mar 2, 2026
…ros2#236) * set default values to avoid errors during collection phase --- In pytest >=8.2.0 the unittest logic has been reworked to work more like a Function/Class, (see pytest-dev/pytest/pull/12089). This has the side-effect that during the collection phase all test are instantiated and given that the __init__ func of TraceTestCase includes required keyword arguments not being fulfilled in the collection phase it errors. This is avoided by setting default values on the __init__ definition so a `TraceTestCase.__init__() ` run during collection phase won't error. pytest changelog: https://docs.pytest.org/en/stable/changelog.html#pytest-8-2-0-2024-04-27 Signed-off-by: claraberendsen <42071084+claraberendsen@users.noreply.github.com> * fix flake8 errors Signed-off-by: claraberendsen <42071084+claraberendsen@users.noreply.github.com> * use single quotes to please flake8 Signed-off-by: claraberendsen <42071084+claraberendsen@users.noreply.github.com> * Use None as default instead of Lists Co-authored-by: Christophe Bedard <bedard.christophe@gmail.com> Signed-off-by: Clara Berendsen <42071084+claraberendsen@users.noreply.github.com> * Manage optional parameters on instantiation Signed-off-by: claraberendsen <42071084+claraberendsen@users.noreply.github.com> --------- Signed-off-by: claraberendsen <42071084+claraberendsen@users.noreply.github.com> Signed-off-by: Clara Berendsen <42071084+claraberendsen@users.noreply.github.com> Co-authored-by: Christophe Bedard <bedard.christophe@gmail.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.
Description
In pytest >=8.2.0 the unittest logic has been reworked to work more like a Function/Class, (see pytest-dev/pytest/pull/12089). This has the side-effect that during the collection phase all test are instantiated and given that the init func of TraceTestCase includes required keyword arguments not being fulfilled in the collection phase it errors.
This is avoided by setting default values on the init definition so a
TraceTestCase.__init__()run during collection phase won't error.pytest changelog: https://docs.pytest.org/en/stable/changelog.html#pytest-8-2-0-2024-04-27
Another approach to solve this would be to set
__test__=falseat the start to prevent pytest from collecting and instantiating the test, however that would need__test__=truefor all of the subclasses ofTraceTestCasethat are actual tests for them to continue working. This seemed more cumbersome than this solution.Fixes regressions on resolute
Is this user-facing behavior change?
Partially, even though default values are set were they would error if not present, this was already the case for two out of the four default keywords implicitly. It won't fail now if those arguments are not set, as it would before for the ones that had no implicit default value.
ros2_tracing/tracetools_test/tracetools_test/case.py
Lines 80 to 82 in 757d1a9
Did you use Generative AI?
No
Additional Information
Reference build:
Build with fixes:
Note that both have failed for reasons different to this PR, but in the later one there are 61 less regressions.