Skip to content

Commit 9b62de7

Browse files
committed
Restore previous environment passed to futurize.py and pasteurize.py when running tests. Also add more output for debugging.
1 parent 0023d65 commit 9b62de7

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

src/future/tests/base.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ def __init__(self, msg, returncode, cmd, output=None):
9090
self.output = output
9191

9292
def __str__(self):
93-
return ("Command '%s' failed with exit status %d\nMessage: %s"
94-
% (self.cmd, self.returncode, self.msg))
93+
return ("Command '%s' failed with exit status %d\nMessage: %s\nOutput: %s"
94+
% (self.cmd, self.returncode, self.msg, self.output))
9595

9696
class PasteurizeError(FuturizeError):
9797
pass
@@ -300,27 +300,37 @@ def _futurize_test_script(self, filename='mytestscript.py', stages=(1, 2),
300300
fn = self.tempdir + filename
301301
call_args = [sys.executable, script] + params + ['-w', fn]
302302
try:
303-
output = check_output(call_args, stderr=STDOUT)
303+
output = check_output(call_args, stderr=STDOUT, env=self.env)
304304
except CalledProcessError as e:
305305
msg = ('Error running the command %s\n%s\nContents of file %s:\n\n%s' %
306306
(' '.join(call_args),
307-
'PYTHONPATH=%s' % os.environ.get('PYTHONPATH'),
307+
'env=%s' % self.env,
308308
fn,
309309
'----\n%s\n----' % open(fn).read(),
310310
)
311311
)
312312
ErrorClass = (FuturizeError if 'futurize' in script else PasteurizeError)
313-
raise ErrorClass(msg, e.returncode, e.cmd)
313+
raise ErrorClass(msg, e.returncode, e.cmd, output=e.output)
314314
return output
315315

316316
def _run_test_script(self, filename='mytestscript.py',
317317
interpreter=sys.executable):
318-
env = {'PYTHONPATH': os.getcwd()}
319-
return check_output([interpreter,
320-
self.tempdir + filename])
321-
# Passing the environment with PYTHONPATH set
322-
# to the python-future source folder causes
323-
# scripts run from that folder to fail on Py3.
318+
# Absolute file path:
319+
fn = self.tempdir + filename
320+
try:
321+
output = check_output([interpreter, fn],
322+
env=self.env, stderr=STDOUT)
323+
except CalledProcessError as e:
324+
msg = ('Error running the command %s\n%s\nContents of file %s:\n\n%s' %
325+
(' '.join([interpreter, fn]),
326+
'env=%s' % self.env,
327+
fn,
328+
'----\n%s\n----' % open(fn).read(),
329+
)
330+
)
331+
ErrorClass = (FuturizeError if 'futurize' in script else PasteurizeError)
332+
raise ErrorClass(msg, e.returncode, e.cmd)
333+
return output
324334

325335

326336
# Decorator to skip some tests on Python 2.6 ...

0 commit comments

Comments
 (0)