From f150d17f07f99b48452f5ab2148b1abda2f52211 Mon Sep 17 00:00:00 2001 From: Benjamin Schubert Date: Fri, 23 Aug 2019 17:18:25 +0100 Subject: 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. --- src/buildstream/sandbox/_mounter.py | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'src/buildstream') 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) -- cgit v1.2.1