diff mbox series

[U-Boot,4/8] test/py: Import StringIO from io module for python 3.x

Message ID 20170914200634.17818-5-paul.burton@imgtec.com
State Deferred
Delegated to: Tom Rini
Headers show
Series test/py: Fixes for python 3.x | expand

Commit Message

Paul Burton Sept. 14, 2017, 8:06 p.m. UTC
In python 3.x the StringIO module is gone, and instead StringIO can be
imported from the io module. Do this in order to run on python 3.x, and
fall back to importing StringIO as a module in order to continue working
with python 2.x.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>
---

 test/py/conftest.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/test/py/conftest.py b/test/py/conftest.py
index dc444cc866..98093540fd 100644
--- a/test/py/conftest.py
+++ b/test/py/conftest.py
@@ -20,7 +20,6 @@  import os.path
 import pytest
 from _pytest.runner import runtestprotocol
 import re
-import StringIO
 import sys
 
 try:
@@ -28,6 +27,11 @@  try:
 except:
     import ConfigParser
 
+try:
+    from StringIO import StringIO
+except ImportError:
+    from io import StringIO
+
 # Globals: The HTML log file, and the connection to the U-Boot console.
 log = None
 console = None
@@ -170,7 +174,7 @@  def pytest_configure(config):
 
         with open(dot_config, 'rt') as f:
             ini_str = '[root]\n' + f.read()
-            ini_sio = StringIO.StringIO(ini_str)
+            ini_sio = StringIO(ini_str)
             parser = ConfigParser.RawConfigParser()
             parser.readfp(ini_sio)
             ubconfig.buildconfig.update(parser.items('root'))