Skip to content

Commit

Permalink
Avoid use of deprecated junit-xml method.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattclay committed Jun 12, 2020
1 parent 26f318d commit 9f49db1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/junit-compat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bugfixes:
- ansible-test - avoid use of deprecated junit_xml method
- junit callback - avoid use of deprecated junit_xml method
11 changes: 10 additions & 1 deletion lib/ansible/plugins/callback/junit.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@

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
Expand Down Expand Up @@ -288,7 +297,7 @@ def _generate_report(self):
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()))

Expand Down
10 changes: 9 additions & 1 deletion test/lib/ansible_test/_internal/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,15 @@ def save_junit(self, args, test_case, properties=None):
),
]

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
Expand Down

0 comments on commit 9f49db1

Please sign in to comment.