summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Schubert <contact@benschubert.me>2019-08-23 17:18:25 +0100
committerBenjamin Schubert <contact@benschubert.me>2019-08-23 17:18:25 +0100
commitf150d17f07f99b48452f5ab2148b1abda2f52211 (patch)
treedf34ba18fdf87e847062552bbe72c727b58f718e
parentfcadd6b5cf3e2eee88f925e2bd4ce9726e2eebf5 (diff)
downloadbuildstream-f150d17f07f99b48452f5ab2148b1abda2f52211.tar.gz
sandbox/_mounter: Remove default mutable arguments stderr/out
stderr and stdout were passed as default arguments and would therefore retain the first value they had when the module was imported, which means they wouldn't get overriden by the pytest capture of stderr/out. This also meant that depending how the mounter was imported, if the stdout/err was patched at that moment, and the file closed, we would get an error. The bug can be reproduced by running: tox -e pyXX -- tests/integration/cmake.py On master, and seeing that it is now fixed.
-rw-r--r--src/buildstream/sandbox/_mounter.py29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/buildstream/sandbox/_mounter.py b/src/buildstream/sandbox/_mounter.py
index e6054c20d..4e31ef67a 100644
--- a/src/buildstream/sandbox/_mounter.py
+++ b/src/buildstream/sandbox/_mounter.py
@@ -28,9 +28,14 @@ from .. import utils, _signals
class Mounter():
@classmethod
def _mount(cls, dest, src=None, mount_type=None,
- stdout=sys.stdout, stderr=sys.stderr, options=None,
+ stdout=None, stderr=None, options=None,
flags=None):
+ if stdout is None:
+ stdout = sys.stdout
+ if stderr is None:
+ stderr = sys.stderr
+
argv = [utils.get_host_tool('mount')]
if mount_type:
argv.extend(['-t', mount_type])
@@ -57,7 +62,11 @@ class Mounter():
return dest
@classmethod
- def _umount(cls, path, stdout=sys.stdout, stderr=sys.stderr):
+ def _umount(cls, path, stdout=None, stderr=None):
+ if stdout is None:
+ stdout = sys.stdout
+ if stderr is None:
+ stderr = sys.stderr
cmd = [utils.get_host_tool('umount'), '-R', path]
status, _ = utils._call(
@@ -89,8 +98,12 @@ class Mounter():
#
@classmethod
@contextmanager
- def mount(cls, dest, src=None, stdout=sys.stdout,
- stderr=sys.stderr, mount_type=None, **kwargs):
+ def mount(cls, dest, src=None, stdout=None,
+ stderr=None, mount_type=None, **kwargs):
+ if stdout is None:
+ stdout = sys.stdout
+ if stderr is None:
+ stderr = sys.stderr
def kill_proc():
cls._umount(dest, stdout, stderr)
@@ -126,8 +139,12 @@ class Mounter():
#
@classmethod
@contextmanager
- def bind_mount(cls, dest, src=None, stdout=sys.stdout,
- stderr=sys.stderr, **kwargs):
+ def bind_mount(cls, dest, src=None, stdout=None,
+ stderr=None, **kwargs):
+ if stdout is None:
+ stdout = sys.stdout
+ if stderr is None:
+ stderr = sys.stderr
def kill_proc():
cls._umount(dest, stdout, stderr)