From 05a1ebec8eeb6bda759bf74e98e60fc53951544a Mon Sep 17 00:00:00 2001 From: Roland Dobai Date: Mon, 5 Oct 2020 11:24:11 +0200 Subject: [PATCH] Fix Python 2/3 compatibility with xmlrunner from unittest_xml_reporting --- setup.py | 1 + test/test_esptool.py | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 4fb7ae507..519d908b9 100644 --- a/setup.py +++ b/setup.py @@ -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=[ diff --git a/test/test_esptool.py b/test/test_esptool.py index 789627fd0..049f60819 100755 --- a/test/test_esptool.py +++ b/test/test_esptool.py @@ -10,6 +10,7 @@ """ from __future__ import division, print_function +import io import os import os.path import re @@ -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)