From 44917596b72ea7d105147e6d3f57af8f10d01446 Mon Sep 17 00:00:00 2001 From: Michel Hidalgo Date: Wed, 21 Aug 2019 12:43:41 -0300 Subject: [PATCH] Mark launch tests explicitly. Signed-off-by: Michel Hidalgo --- launch_testing/launch_testing/pytest/hooks.py | 16 +++++++++++++--- .../launch_testing/examples/args_launch_test.py | 4 ++++ .../examples/context_launch_test.py | 3 +++ .../examples/good_proc_launch_test.py | 3 +++ .../examples/parameters_launch_test.py | 3 +++ .../examples/terminating_proc_launch_test.py | 3 +++ 6 files changed, 29 insertions(+), 3 deletions(-) diff --git a/launch_testing/launch_testing/pytest/hooks.py b/launch_testing/launch_testing/pytest/hooks.py index 2c56b42f9..cd0756a83 100644 --- a/launch_testing/launch_testing/pytest/hooks.py +++ b/launch_testing/launch_testing/pytest/hooks.py @@ -99,17 +99,21 @@ def pytest_pycollect_makemodule(path, parent): entrypoint = find_launch_test_entrypoint(path) if entrypoint is not None: ihook = parent.session.gethookproxy(path) - return ihook.pytest_launch_collect_makemodule( + module = ihook.pytest_launch_collect_makemodule( path=path, parent=parent, entrypoint=entrypoint ) - elif path.basename == '__init__.py': + if module is not None: + return module + if path.basename == '__init__.py': return pytest.Package(path, parent) return pytest.Module(path, parent) @pytest.hookimpl(trylast=True) def pytest_launch_collect_makemodule(path, parent, entrypoint): - return LaunchTestModule(path, parent) + marks = getattr(entrypoint, 'pytestmark', []) + if marks and any(m.name == 'launch_test' for m in marks): + return LaunchTestModule(path, parent) def pytest_addhooks(pluginmanager): @@ -122,3 +126,9 @@ def pytest_addoption(parser): '--launch-args', action='append', nargs='*', default=[], help='One or more Launch test arguments' ) + + +def pytest_configure(config): + config.addinivalue_line( + 'markers', 'launch_test: mark a generate_test_description function as a launch test entrypoint' + ) diff --git a/launch_testing/test/launch_testing/examples/args_launch_test.py b/launch_testing/test/launch_testing/examples/args_launch_test.py index 23492aecf..891efeeda 100644 --- a/launch_testing/test/launch_testing/examples/args_launch_test.py +++ b/launch_testing/test/launch_testing/examples/args_launch_test.py @@ -25,6 +25,9 @@ import launch_testing import launch_testing.util +import pytest + + dut_process = launch.actions.ExecuteProcess( cmd=[ sys.executable, @@ -40,6 +43,7 @@ ) +@pytest.mark.launch_test def generate_test_description(ready_fn): return launch.LaunchDescription([ diff --git a/launch_testing/test/launch_testing/examples/context_launch_test.py b/launch_testing/test/launch_testing/examples/context_launch_test.py index df4df3558..6adafc853 100644 --- a/launch_testing/test/launch_testing/examples/context_launch_test.py +++ b/launch_testing/test/launch_testing/examples/context_launch_test.py @@ -24,6 +24,8 @@ import launch_testing from launch_testing.asserts import assertSequentialStdout +import pytest + def get_test_process_action(): TEST_PROC_PATH = os.path.join( @@ -42,6 +44,7 @@ def get_test_process_action(): # This launch description shows the prefered way to let the tests access launch actions. By # adding them to the test context, it's not necessary to scope them at the module level like in # the good_proc.test.py example +@pytest.mark.launch_test def generate_test_description(ready_fn): dut_process = get_test_process_action() diff --git a/launch_testing/test/launch_testing/examples/good_proc_launch_test.py b/launch_testing/test/launch_testing/examples/good_proc_launch_test.py index a72aa9dc6..215dffeb1 100644 --- a/launch_testing/test/launch_testing/examples/good_proc_launch_test.py +++ b/launch_testing/test/launch_testing/examples/good_proc_launch_test.py @@ -24,6 +24,8 @@ import launch_testing from launch_testing.asserts import assertSequentialStdout +import pytest + TEST_PROC_PATH = os.path.join( ament_index_python.get_package_prefix('launch_testing'), @@ -41,6 +43,7 @@ ) +@pytest.mark.launch_test def generate_test_description(ready_fn): return launch.LaunchDescription([ diff --git a/launch_testing/test/launch_testing/examples/parameters_launch_test.py b/launch_testing/test/launch_testing/examples/parameters_launch_test.py index 69fefa62d..4596e81e9 100644 --- a/launch_testing/test/launch_testing/examples/parameters_launch_test.py +++ b/launch_testing/test/launch_testing/examples/parameters_launch_test.py @@ -23,7 +23,10 @@ import launch_testing import launch_testing.util +import pytest + +@pytest.mark.launch_test @launch_testing.parametrize('arg_param', ['thing=On', 'thing=Off', 'flag1']) def generate_test_description(arg_param, ready_fn): diff --git a/launch_testing/test/launch_testing/examples/terminating_proc_launch_test.py b/launch_testing/test/launch_testing/examples/terminating_proc_launch_test.py index a6d78331c..cbcadebec 100644 --- a/launch_testing/test/launch_testing/examples/terminating_proc_launch_test.py +++ b/launch_testing/test/launch_testing/examples/terminating_proc_launch_test.py @@ -25,6 +25,8 @@ import launch_testing.asserts import launch_testing.tools +import pytest + def get_test_process_action(*, args=[]): test_proc_path = os.path.join( @@ -40,6 +42,7 @@ def get_test_process_action(*, args=[]): ) +@pytest.mark.launch_test def generate_test_description(ready_fn): return launch.LaunchDescription([ launch_testing.util.KeepAliveProc(),