Skip to content
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

Support launch_ros test runner in pytest #54

Merged
merged 7 commits into from
Aug 23, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
195 changes: 0 additions & 195 deletions launch_testing_ros/examples/talker_listener.test.py

This file was deleted.

Empty file.
42 changes: 42 additions & 0 deletions launch_testing_ros/launch_testing_ros/pytest/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2019 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from launch_testing.pytest.hooks import LaunchTestItem
from launch_testing.pytest.hooks import LaunchTestModule

from ..test_runner import LaunchTestRunner


class LaunchROSTestItem(LaunchTestItem):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs, runner_cls=LaunchTestRunner)


class LaunchROSTestModule(LaunchTestModule):

def makeitem(self, *args, **kwargs):
return LaunchROSTestItem(*args, **kwargs)


def pytest_launch_collect_makemodule(path, parent, entrypoint):
marks = getattr(entrypoint, 'pytestmark', [])
if marks and len(marks) == 1 and marks[0].name == 'rostest':
return LaunchROSTestModule(path, parent)


def pytest_configure(config):
config.addinivalue_line(
'markers', 'rostest: mark a launch test as a ROS launch test'
)
3 changes: 3 additions & 0 deletions launch_testing_ros/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
('lib/launch_testing_ros', glob.glob('example_nodes/**')),
('share/launch_testing_ros/examples', glob.glob('examples/[!_]**')),
],
entry_points={
'pytest11': ['launch_ros = launch_testing_ros.pytest.hooks'],
},
install_requires=['setuptools'],
zip_safe=True,
author='Pete Baughman',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,23 @@
# Examples

## `talker_listener.test.py`
ivanpauno marked this conversation as resolved.
Show resolved Hide resolved
## `talker_listener_launch_test.py`

Usage:
> launch_test examples/talker_listener.test.py
> launch\_test talker_listener\_launch\_test.py

This test launches the talker and listener example nodes from demo_nodes_py and interacts
This test launches the talker and listener example nodes from demo\_nodes\_py and interacts
with them via their ROS interfaces. Remapping rules are used so that one of the tests can sit in
between the talker and the listener and change the data on the fly.

Node that in the setUpClass method, the test makes sure that the listener is subscribed and
republishing messages. Since the listener process provides no synchronization mechanism to
inform the outside world that it's up and running, this step is necessary especially in resource
constrained environments where process startup may take a non negligible amount of time. This
is often the cause of "flakyness" in tests on CI systems. A more robust design of the talker and
listener processes might provide some positive feedback that the node is up and running, but these
are simple example nodes.

#### test_fuzzy_data
#### test\_fuzzy\_data
This test gives an example of what a test that fuzzes data might look like. A ROS subscriber
and publisher pair encapsulated in a `DataRepublisher` object changes the string "Hello World" to
"Aloha World" as it travels between the talker and the listener.

#### test_listener_receives
#### test\_listener\_receives
This test publishes unique messages on the `/chatter` topic and asserts that the same messages
go to the stdout of the listener node

#### test_talker_transmits
#### test\_talker\_transmits
This test subscribes to the remapped `/talker_chatter` topic and makes sure the talker node also
writes the data it's transmitting to stdout
Loading