-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
First prototype of native pytest plugin for launch based tests #528
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First pass, great stuff!
): | ||
mod_locals[name] = getter(scope) | ||
else: | ||
mod_locals[name] = getter(scope) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ivanpauno I think I understand the override-able fixture magic, but doesn't this imply fixtures of different scopes cannot coexist in the same source file? I mean, you could have 3 tests using a module scope fixture and 3 tests using a function scope fixture and there wouldn't be any overlap, would it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you have one launch_test fixture with class
scope and one with function
scope, the launch_service function will be class scoped.
This is required because of the following issue:
@pytest.fixture()
def foo():
...
@pytest.fixture(scope='module')
def bar(foo):
...
In that case you get a "scope mismatch error", because you cannot access a fixture with a lower scope from another fixture.
The fact that the launch_service/event_loop is automatically redefined with a larger scope only means that it might be shared by both launch_test fixtures, which is not necessarly a problem.
We could actually create one launch_service per launch_test fixture, and don't use a fixture for that at all.
For the event_loop though, you can only have one active event loop in a thread, so it would be an issue anyway.
Maybe in the future pytest solves this issue, see pytest-dev/pytest#6101.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case you get a "scope mismatch error", because you cannot access a fixture with a lower scope from another fixture.
Aye, the launch_service
fixture scope has to be at least as large as the largest scope of all launch fixtures found (BTW isn't that example reversed?).
The fact that the launch_service/event_loop is automatically redefined with a larger scope only means that it might be shared by both launch_test fixtures, which is not necessarly a problem.
I see two problems. Unrelated larger scope fixtures creeping into tests with smaller scope fixtures, and a large scope launch fixture being shutdown (which IIRC is a terminal state) by a smaller scope fixture upon finalization. The first one is not really a problem if we enforce a 1-to-1 relationship between tests and launch fixtures. The second one is.
We could actually create one launch_service per launch_test fixture, and don't use a fixture for that at all.
Having separate instances is probably easiest, yeah. Alternatively, we can make LaunchService
shutdowns not a terminal state (i.e. allow re-running after a shutdown).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(BTW isn't that example reversed?).
lol yes, fixed.
and a large scope launch fixture being shutdown (which IIRC is a terminal state) by a smaller scope fixture upon finalization
Yes, I think we can detect that case and warn the user though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a few comments, but honestly the pytest stuff is a bit over my head (opaque without some special knowledge it seems).
launch_testing/test/launch_testing/new_hooks/test_function_scope.py
Outdated
Show resolved
Hide resolved
On a related note, would it make sense to roll out a separate |
The imports wouldn't really be much shorter. There're a few things that I can reuse from the current launch_testing though, like the |
Maybe, to some extent. We can probably do better but it's not a bad start. |
@hidmic could you take another look? I have added support for shutdown tests, including generator/asyncgenerators based ones. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, I left some comments, questions, suggestions, and ideas. This is complex code, sorry if I mixed things up 😅
args[name] = value | ||
if inspect.iscoroutinefunction(func): | ||
pyfuncitem.obj = wrap_coroutine(func, args, event_loop, before_test) | ||
elif inspect.isgeneratorfunction(func): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ivanpauno meta: does it make sense to have pure post-shutdown tests that are sync or async generators?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really, I think the shutdown flag is being ignored in that case, though maybe better we should show an error.
I'm also having problems to support pure post-shutdown tests, so maybe I'll delete that option altogether.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See bf8c790
On the one hand, replacing Because of that, my inclination is to make a new package, and once that is in have On a different meta-note, I'd also like to see some examples on how to use this new functionality in downstream packages. For instance, how would I change https://github.com/ros-teleop/teleop_tools/blob/foxy-devel/joy_teleop/test/test_action_fibonacci.py to use this new package? Maybe those examples should be in here, or maybe they should be over in https://github.com/ros2/examples, or maybe they should be in the documentation. |
This pull request has been mentioned on ROS Discourse. There might be relevant details there: https://discourse.ros.org/t/ros-2-tsc-meeting-minutes-2021-9-16/22372/1 |
I'm fine with this approach, to be honest. It also opens us up to being able to do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Second (or third?) pass!
raise RuntimeError( | ||
'launch_pytest fixtures must return a LaunchDescription ' | ||
'containing only one ReadyToTest action' | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ivanpauno meta: just like launch_testing
, this cannot really detect all ReadyToTest
instances (thinking of includes). We need to document the fact that we'll simply pick up the first one found we can statically find. In which case, I'm slightly inclined to make this a warning. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A warn would be fine as well.
launch_testing/test/launch_testing/new_hooks/test_function_scope.py
Outdated
Show resolved
Hide resolved
return launch.LaunchDescription([ | ||
launch_testing.util.KeepAliveProc(), | ||
launch_testing.actions.ReadyToTest(), | ||
]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ivanpauno It'd be nice to test a launch_description
that yields (though I don't see why it wouldn't work)
FYI, force-pushed to rebase with master |
332ddf2
to
46ae686
Compare
The reason why the Rpr checker fails is interesting. It seems that we're using the pip installed pytest in the buildfarm, due to I'm not using much of |
Note to self: Make sure our plugin works with both the pip and debian package version of pytest. |
Issue fixed in 8514c4e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is amazing @ivanpauno.
Barring minor comments, I'm happy with it if CI's happy with it.
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
74bbec3
to
af0c896
Compare
Force pushed to resolve conflicts after #454 was merged. |
This reverts commit af0c896. Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
This pull request has been mentioned on ROS Discourse. There might be relevant details there: https://discourse.ros.org/t/ros-2-tsc-meeting-minutes-2021-10-28/22947/1 |
@ivanpauno Can I ask you to take a look to this PR? it introduced some regressions to the repeated jobs of the buildfarm: nightly_linux_repeated#2459 I imagine it's missing a cleanup that's only showing once the tests are run in a sequence. |
Interesting... I will take a look |
This pull request has been mentioned on ROS Discourse. There might be relevant details there: https://discourse.ros.org/t/ros-2-tsc-meeting-minutes-2021-11-18/23209/1 |
@ivanpauno @hidmic Is backporting |
I think that up to now it hasn't been used enough to say it's worth backporting. |
Some early discussion can be found here: https://gist.github.com/ivanpauno/761a7cbca83335ea081512f3494304ba.
I'm planning to add support for shutdown tests.
There are also a lot of other details that can be discussed.