Skip to content

Commit

Permalink
Fix Python 2/3 compatibility with xmlrunner from unittest_xml_reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
dobairoland committed Oct 7, 2020
1 parent 104dc5d commit 05a1ebe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def find_version(*file_paths):
'flake8-future-import',
'flake8-import-order',
'pyelftools',
'unittest-xml-reporting<=2.5.2', # the replacement of the old xmlrunner package (Python 2 comp. version)
],
},
install_requires=[
Expand Down
17 changes: 13 additions & 4 deletions test/test_esptool.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"""
from __future__ import division, print_function

import io
import os
import os.path
import re
Expand Down Expand Up @@ -698,10 +699,18 @@ def test_auto_detect_virtual_port(self):

print("Running esptool.py tests...")
try:
import xmlrunner
import xmlrunner # it should come from the unittest-xml-reporting package and not from xmlrunner
import pkg_resources

with open('report.xml', 'w' if sys.version[0] == '2' else 'wb') as output:
unittest.main(
testRunner=xmlrunner.XMLTestRunner(output=output))
try:
pkg_resources.require('xmlrunner')
raise ImportError('The unittest-xml-reporting package should be used instead of xmlrunner')
except pkg_resources.DistributionNotFound:
# it is desired that xmlrunner is not installed so it will not interfere with unittest-xml-reporting
# (conflict of files)
pass

with io.open('report.xml', 'wb') as output:
unittest.main(testRunner=xmlrunner.XMLTestRunner(output=output))
except ImportError:
unittest.main(buffer=True)

0 comments on commit 05a1ebe

Please sign in to comment.