Skip to content

Commit

Permalink
Mark launch tests explicitly.
Browse files Browse the repository at this point in the history
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
  • Loading branch information
hidmic committed Aug 21, 2019
1 parent 8014b4c commit 4491759
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 3 deletions.
16 changes: 13 additions & 3 deletions launch_testing/launch_testing/pytest/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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'
)
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
import launch_testing
import launch_testing.util

import pytest


dut_process = launch.actions.ExecuteProcess(
cmd=[
sys.executable,
Expand All @@ -40,6 +43,7 @@
)


@pytest.mark.launch_test
def generate_test_description(ready_fn):

return launch.LaunchDescription([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -41,6 +43,7 @@
)


@pytest.mark.launch_test
def generate_test_description(ready_fn):

return launch.LaunchDescription([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(),
Expand Down

0 comments on commit 4491759

Please sign in to comment.