summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Clay <matt@mystile.com>2020-06-12 03:52:46 +0200
committerMatt Clay <matt@mystile.com>2020-06-12 09:47:07 +0200
commit9f49db1f9999a0b914bc4bc05ab55b782d429f9a (patch)
treec1f8f2fea32d335733add5c73a17041c4a98d666
parentIgnore return code from antsibull_changelog lint. (diff)
downloadansible-9f49db1f9999a0b914bc4bc05ab55b782d429f9a.tar.xz
ansible-9f49db1f9999a0b914bc4bc05ab55b782d429f9a.zip
Avoid use of deprecated junit-xml method.
-rw-r--r--changelogs/fragments/junit-compat.yml3
-rw-r--r--lib/ansible/plugins/callback/junit.py11
-rw-r--r--test/lib/ansible_test/_internal/test.py10
3 files changed, 22 insertions, 2 deletions
diff --git a/changelogs/fragments/junit-compat.yml b/changelogs/fragments/junit-compat.yml
new file mode 100644
index 0000000000..1de3270497
--- /dev/null
+++ b/changelogs/fragments/junit-compat.yml
@@ -0,0 +1,3 @@
+bugfixes:
+ - ansible-test - avoid use of deprecated junit_xml method
+ - junit callback - avoid use of deprecated junit_xml method
diff --git a/lib/ansible/plugins/callback/junit.py b/lib/ansible/plugins/callback/junit.py
index a7f106a1b3..2fc892924d 100644
--- a/lib/ansible/plugins/callback/junit.py
+++ b/lib/ansible/plugins/callback/junit.py
@@ -86,6 +86,15 @@ from ansible.plugins.callback import CallbackBase
try:
from junit_xml import TestSuite, TestCase
+
+ # the junit_xml API is changing in version 2.0.0
+ # TestSuite.to_xml_string is being replaced with to_xml_report_string
+ # see: https://github.com/kyrus/python-junit-xml/blob/63db26da353790500642fd02cae1543eb41aab8b/junit_xml/__init__.py#L249-L261
+ try:
+ from junit_xml import to_xml_report_string
+ except ImportError:
+ to_xml_report_string = TestSuite.to_xml_string
+
HAS_JUNIT_XML = True
except ImportError:
HAS_JUNIT_XML = False
@@ -288,7 +297,7 @@ class CallbackModule(CallbackBase):
test_cases.append(self._build_test_case(task_data, host_data))
test_suite = TestSuite(self._playbook_name, test_cases)
- report = TestSuite.to_xml_string([test_suite])
+ report = to_xml_report_string([test_suite])
output_file = os.path.join(self._output_dir, '%s-%s.xml' % (self._playbook_name, time.time()))
diff --git a/test/lib/ansible_test/_internal/test.py b/test/lib/ansible_test/_internal/test.py
index 42a23da3fd..8d9629a9db 100644
--- a/test/lib/ansible_test/_internal/test.py
+++ b/test/lib/ansible_test/_internal/test.py
@@ -151,7 +151,15 @@ class TestResult:
),
]
- report = self.junit.TestSuite.to_xml_string(test_suites=test_suites, prettyprint=True, encoding='utf-8')
+ # the junit_xml API is changing in version 2.0.0
+ # TestSuite.to_xml_string is being replaced with to_xml_report_string
+ # see: https://github.com/kyrus/python-junit-xml/blob/63db26da353790500642fd02cae1543eb41aab8b/junit_xml/__init__.py#L249-L261
+ try:
+ to_xml_string = self.junit.to_xml_report_string
+ except AttributeError:
+ to_xml_string = self.junit.TestSuite.to_xml_string
+
+ report = to_xml_string(test_suites=test_suites, prettyprint=True, encoding='utf-8')
if args.explain:
return