Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix capture output when running tests that call the ConanRunner in the conanfile #7799

Merged
merged 2 commits into from Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions conans/client/runner.py
Expand Up @@ -14,7 +14,7 @@

class _UnbufferedWrite(object):
def __init__(self, stream):
self._stream = stream
self._stream = stream._stream if hasattr(stream, "_stream") else stream

def write(self, *args, **kwargs):
self._stream.write(*args, **kwargs)
Expand Down Expand Up @@ -43,7 +43,7 @@ def __call__(self, command, output=True, log_filepath=None, cwd=None, subprocess
"use six.StringIO() instead ***")

stream_output = output if output and hasattr(output, "write") else self._output or sys.stdout
if hasattr(output, "flush"):
if hasattr(stream_output, "flush"):
# We do not want output from different streams to get mixed (sys.stdout, os.system)
stream_output = _UnbufferedWrite(stream_output)

Expand Down
13 changes: 13 additions & 0 deletions conans/test/functional/conanfile/runner_test.py
@@ -1,4 +1,5 @@
import os
import textwrap
import unittest

import six
Expand Down Expand Up @@ -180,3 +181,15 @@ def build(self):
client.run("build .", assert_error=True)
self.assertIn("Error while executing 'mkdir test_folder'", client.out)
self.assertFalse(os.path.exists(test_folder))

def runner_capture_output_test(self):
conanfile = textwrap.dedent("""
from conans import ConanFile
class Pkg(ConanFile):
def source(self):
self.run("echo 'hello Conan!'")
""")
client = TestClient()
client.save({"conanfile.py": conanfile})
client.run("source .")
self.assertIn("hello Conan!", client.out)