Skip to content
This repository has been archived by the owner on Jan 27, 2020. It is now read-only.

Allow parametrization to test descriptions #39

Merged
merged 6 commits into from
Apr 19, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions apex_launchtest/apex_launchtest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@

from .decorator import post_shutdown_test
from .io_handler import ActiveIoHandler, IoHandler
from .parametrize import parametrize
from .proc_info_handler import ActiveProcInfoHandler, ProcInfoHandler
from .ready_aggregator import ReadyAggregator

__all__ = [
# Functions
'parametrize',
'post_shutdown_test',

# Classes
Expand Down
36 changes: 18 additions & 18 deletions apex_launchtest/apex_launchtest/apex_launchtest_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from .apex_runner import ApexRunner
from .domain_coordinator import get_coordinated_domain_id
from .junitxml import unittestResultsToXml
from .loader import LoadTestsFromPythonModule
from .print_arguments import print_arguments_of_launch_description

_logger_ = logging.getLogger(__name__)
Expand All @@ -29,7 +30,10 @@
def _load_python_file_as_module(python_file_path):
"""Load a given Python launch file (by path) as a Python module."""
# Taken from apex_core to not introduce a weird dependency thing
loader = SourceFileLoader('python_launch_file', python_file_path)
loader = SourceFileLoader(
os.path.basename(python_file_path),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will give the tests a better name in the resulting XML. The TestRun class in loader.py uses the module name to construct the name of the test run. This information eventually makes it into the junit XML file and makes it a little easier to see where tests came from, and what parameters they ran with.

python_file_path
)
return loader.load_module()


Expand Down Expand Up @@ -99,12 +103,13 @@ def apex_launchtest_main():
"Test file '{}' is missing generate_test_description function".format(args.test_file)
)

dut_test_description_func = test_module.generate_test_description
_logger_.debug('Checking generate_test_description function signature')
# This is a list of TestRun objects. Each run corresponds to one launch. There may be
# multiple runs if the launch is parametrized
test_runs = LoadTestsFromPythonModule(test_module)

# The runner handles sequcing the launches
runner = ApexRunner(
gen_launch_description_fn=dut_test_description_func,
test_module=test_module,
test_runs=test_runs,
launch_file_arguments=args.launch_arguments,
debug=args.verbose
)
Expand All @@ -116,30 +121,25 @@ def apex_launchtest_main():
parser.error(e)

if args.show_args:
# TODO pete: Handle the case where different launch descriptions take different args?
print_arguments_of_launch_description(
launch_description=runner.get_launch_description()
launch_description=test_runs[0].get_launch_description()
)
sys.exit(0)

_logger_.debug('Running integration test')
try:
result, postcheck_result = runner.run()
results = runner.run()
_logger_.debug('Done running integration test')

if args.xmlpath:
xml_report = unittestResultsToXml(
test_results={
'active_tests': result,
'after_shutdown_tests': postcheck_result
}
)
xml_report = unittestResultsToXml(test_results=results)
xml_report.write(args.xmlpath, xml_declaration=True)

if not result.wasSuccessful():
sys.exit(1)

if not postcheck_result.wasSuccessful():
sys.exit(1)
# There will be one result for every test run (see above where we load the tests)
for result in results.values():
if not result.wasSuccessful():
sys.exit(1)

except Exception as e:
import traceback
Expand Down
Loading