Skip to content

Set default values on TraceTestCase to avoid errors on >=8.2.0 pytest#236

Merged
claraberendsen merged 5 commits into
ros2:rollingfrom
claraberendsen:claraberendsen/fix-resolute-errors
Feb 26, 2026
Merged

Set default values on TraceTestCase to avoid errors on >=8.2.0 pytest#236
claraberendsen merged 5 commits into
ros2:rollingfrom
claraberendsen:claraberendsen/fix-resolute-errors

Conversation

@claraberendsen
Copy link
Copy Markdown
Contributor

@claraberendsen claraberendsen commented Feb 25, 2026

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__=false at the start to prevent pytest from collecting and instantiating the test, however that would need __test__=true for all of the subclasses of TraceTestCase that 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.

self._session_name_prefix = \
session_name_prefix + ('__' + rmw_implementation if rmw_implementation else '')
self._events_ros = events_ros + [TRACE_TEST_ID_TP_NAME]

Did you use Generative AI?

No

Additional Information

Reference build: Build Status

Build with fixes: Build Status

Note that both have failed for reasons different to this PR, but in the later one there are 61 less regressions.

@claraberendsen claraberendsen changed the title set default values to avoid errors during collection phase Set default values on TraceTestCase to avoid errors on >=8.2.0 pytest Feb 25, 2026
---
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>
@claraberendsen claraberendsen force-pushed the claraberendsen/fix-resolute-errors branch 2 times, most recently from 8f8dd67 to 8b630dc Compare February 25, 2026 14:13
Signed-off-by: claraberendsen <42071084+claraberendsen@users.noreply.github.com>
@claraberendsen claraberendsen force-pushed the claraberendsen/fix-resolute-errors branch from 8b630dc to af7b648 Compare February 25, 2026 14:33
Signed-off-by: claraberendsen <42071084+claraberendsen@users.noreply.github.com>
Copy link
Copy Markdown
Member

@christophebedard christophebedard left a comment

Choose a reason for hiding this comment

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

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

Comment thread tracetools_test/tracetools_test/case.py Outdated
Co-authored-by: Christophe Bedard <bedard.christophe@gmail.com>
Signed-off-by: Clara Berendsen <42071084+claraberendsen@users.noreply.github.com>
@claraberendsen claraberendsen force-pushed the claraberendsen/fix-resolute-errors branch from 9c5c046 to 36f54aa Compare February 26, 2026 14:21
Signed-off-by: claraberendsen <42071084+claraberendsen@users.noreply.github.com>
@claraberendsen claraberendsen self-assigned this Feb 26, 2026
@claraberendsen
Copy link
Copy Markdown
Contributor Author

Pulls: #236
Gist: https://gist.githubusercontent.com/claraberendsen/685e45f6ed27e02cdfab5a0e3ba0e73a/raw/d757847a7f509b8f97fdfd8e42c0a3f72f1ce397/ros2.repos
BUILD args: --packages-above-and-dependencies tracetools_test
TEST args: --packages-above tracetools_test
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/18329

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

@claraberendsen claraberendsen merged commit dc7b079 into ros2:rolling Feb 26, 2026
9 checks passed
@claraberendsen claraberendsen deleted the claraberendsen/fix-resolute-errors branch February 26, 2026 17:30
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants