felixdivo / ros2-easy-test

A Python test framework for ROS2 allowing simple and expressive assertions based on message interactions.
https://ros2-easy-test.readthedocs.io
MIT License
15 stars 5 forks source link

Support parallel test execution #14

Open felixdivo opened 1 year ago

felixdivo commented 1 year ago

We can use isolated ROS2 partitions to run tests in parallel. This is very useful with pytest-parallel, e.g. when you can run pytest --workers $((2 * $(nproc))). For this, you need to set the ROS_DOMAIN_ID:

import os
import random
if use_random_domain_id:
    if "ROS_DOMAIN_ID" in os.environ:
        warn("the user about the fact that they already specified it")
    os.environ["ROS_DOMAIN_ID"] = str(random.randint(0, 232))  # or maybe more clever?
felixdivo commented 1 year ago

One can also pass domain_id to rclpy.Context.init() (relevant for @with_single_node).