From e2f85b3f6cfd56846e65cad51c5fe47c551e72dd Mon Sep 17 00:00:00 2001 From: sdirbach Date: Mon, 3 Dec 2018 19:41:44 +0100 Subject: [PATCH] Implement test case prefix to filter test cases (#40174) * Implement test case prefix to filter test cases * Cut line to not exceed 160 chars * Replace tabs with spaces * Add version_added field * Include changelog file --- .../40174-junit-test-case-prefix-filter.yaml | 3 +++ lib/ansible/plugins/callback/junit.py | 14 +++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/40174-junit-test-case-prefix-filter.yaml diff --git a/changelogs/fragments/40174-junit-test-case-prefix-filter.yaml b/changelogs/fragments/40174-junit-test-case-prefix-filter.yaml new file mode 100644 index 00000000000..d0ff10ce68a --- /dev/null +++ b/changelogs/fragments/40174-junit-test-case-prefix-filter.yaml @@ -0,0 +1,3 @@ +--- +minor_changes: +- junit callback plug-in - introduce a new option to consider a task only as test case if it has this value as prefix. diff --git a/lib/ansible/plugins/callback/junit.py b/lib/ansible/plugins/callback/junit.py index 3492f55305b..a7f106a1b3d 100644 --- a/lib/ansible/plugins/callback/junit.py +++ b/lib/ansible/plugins/callback/junit.py @@ -65,6 +65,13 @@ DOCUMENTATION = ''' version_added: "2.8" env: - name: JUNIT_HIDE_TASK_ARGUMENTS + test_case_prefix: + name: Prefix to find actual test cases + default: + description: Consider a task only as test case if it has this value as prefix. Additionaly failing tasks are recorded as failed test cases. + version_added: "2.8" + env: + - name: JUNIT_TEST_CASE_PREFIX requirements: - whitelist in configuration - junit_xml (python lib) @@ -122,6 +129,9 @@ class CallbackModule(CallbackBase): Default: True JUNIT_HIDE_TASK_ARGUMENTS (optional): Hide the arguments for a task Default: False + JUNIT_TEST_CASE_PREFIX (optional): Consider a task only as test case if it has this value as prefix. Additionaly failing tasks are recorded as failed + test cases. + Default: Requires: junit_xml @@ -143,6 +153,7 @@ class CallbackModule(CallbackBase): self._fail_on_ignore = os.getenv('JUNIT_FAIL_ON_IGNORE', 'False').lower() self._include_setup_tasks_in_report = os.getenv('JUNIT_INCLUDE_SETUP_TASKS_IN_REPORT', 'True').lower() self._hide_task_arguments = os.getenv('JUNIT_HIDE_TASK_ARGUMENTS', 'False').lower() + self._test_case_prefix = os.getenv('JUNIT_TEST_CASE_PREFIX', '') self._playbook_path = None self._playbook_name = None self._play_name = None @@ -211,7 +222,8 @@ class CallbackModule(CallbackBase): elif status == 'ok': status = 'failed' - task_data.add_host(HostData(host_uuid, host_name, status, result)) + if task_data.name.startswith(self._test_case_prefix) or status == 'failed': + task_data.add_host(HostData(host_uuid, host_name, status, result)) def _build_test_case(self, task_data, host_data): """ build a TestCase from the given TaskData and HostData """