summaryrefslogtreecommitdiff
path: root/test/lib/ansible_test/_util/target/sanity/import/importer.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/lib/ansible_test/_util/target/sanity/import/importer.py')
-rw-r--r--test/lib/ansible_test/_util/target/sanity/import/importer.py24
1 files changed, 13 insertions, 11 deletions
diff --git a/test/lib/ansible_test/_util/target/sanity/import/importer.py b/test/lib/ansible_test/_util/target/sanity/import/importer.py
index 3dcb8bf934..3180530c95 100644
--- a/test/lib/ansible_test/_util/target/sanity/import/importer.py
+++ b/test/lib/ansible_test/_util/target/sanity/import/importer.py
@@ -48,11 +48,7 @@ def main():
__import__(name)
return sys.modules[name]
- try:
- # noinspection PyCompatibility
- from StringIO import StringIO
- except ImportError:
- from io import StringIO
+ from io import BytesIO, TextIOWrapper
try:
from importlib.util import spec_from_loader, module_from_spec
@@ -436,8 +432,9 @@ def main():
class Capture:
"""Captured output and/or exception."""
def __init__(self):
- self.stdout = StringIO()
- self.stderr = StringIO()
+ # use buffered IO to simulate StringIO; allows Ansible's stream patching to behave without warnings
+ self.stdout = TextIOWrapper(BytesIO())
+ self.stderr = TextIOWrapper(BytesIO())
def capture_report(path, capture, messages):
"""Report on captured output.
@@ -445,12 +442,17 @@ def main():
:type capture: Capture
:type messages: set[str]
"""
- if capture.stdout.getvalue():
- first = capture.stdout.getvalue().strip().splitlines()[0].strip()
+ # since we're using buffered IO, flush before checking for data
+ capture.stdout.flush()
+ capture.stderr.flush()
+ stdout_value = capture.stdout.buffer.getvalue()
+ if stdout_value:
+ first = stdout_value.decode().strip().splitlines()[0].strip()
report_message(path, 0, 0, 'stdout', first, messages)
- if capture.stderr.getvalue():
- first = capture.stderr.getvalue().strip().splitlines()[0].strip()
+ stderr_value = capture.stderr.buffer.getvalue()
+ if stderr_value:
+ first = stderr_value.decode().strip().splitlines()[0].strip()
report_message(path, 0, 0, 'stderr', first, messages)
def report_message(path, line, column, code, message, messages):