##// END OF EJS Templates
run-tests: add env dict to isolate test environment
Matt Mackall -
r19262:7864e8f2 default
parent child Browse files
Show More
@@ -62,9 +62,9 b' import Queue as queue'
62 processlock = threading.Lock()
62 processlock = threading.Lock()
63
63
64 closefds = os.name == 'posix'
64 closefds = os.name == 'posix'
65 def Popen4(cmd, wd, timeout):
65 def Popen4(cmd, wd, timeout, env=None):
66 processlock.acquire()
66 processlock.acquire()
67 p = subprocess.Popen(cmd, shell=True, bufsize=-1, cwd=wd,
67 p = subprocess.Popen(cmd, shell=True, bufsize=-1, cwd=wd, env=env,
68 close_fds=closefds,
68 close_fds=closefds,
69 stdin=subprocess.PIPE, stdout=subprocess.PIPE,
69 stdin=subprocess.PIPE, stdout=subprocess.PIPE,
70 stderr=subprocess.STDOUT)
70 stderr=subprocess.STDOUT)
@@ -549,13 +549,13 b' def outputcoverage(options):'
549 os.mkdir(adir)
549 os.mkdir(adir)
550 covrun('-i', '-a', '"--directory=%s"' % adir, '"--omit=%s"' % omit)
550 covrun('-i', '-a', '"--directory=%s"' % adir, '"--omit=%s"' % omit)
551
551
552 def pytest(test, wd, options, replacements):
552 def pytest(test, wd, options, replacements, env):
553 py3kswitch = options.py3k_warnings and ' -3' or ''
553 py3kswitch = options.py3k_warnings and ' -3' or ''
554 cmd = '%s%s "%s"' % (PYTHON, py3kswitch, test)
554 cmd = '%s%s "%s"' % (PYTHON, py3kswitch, test)
555 vlog("# Running", cmd)
555 vlog("# Running", cmd)
556 if os.name == 'nt':
556 if os.name == 'nt':
557 replacements.append((r'\r\n', '\n'))
557 replacements.append((r'\r\n', '\n'))
558 return run(cmd, wd, options, replacements)
558 return run(cmd, wd, options, replacements, env)
559
559
560 needescape = re.compile(r'[\x00-\x08\x0b-\x1f\x7f-\xff]').search
560 needescape = re.compile(r'[\x00-\x08\x0b-\x1f\x7f-\xff]').search
561 escapesub = re.compile(r'[\x00-\x08\x0b-\x1f\\\x7f-\xff]').sub
561 escapesub = re.compile(r'[\x00-\x08\x0b-\x1f\\\x7f-\xff]').sub
@@ -615,7 +615,7 b' def linematch(el, l):'
615 return True
615 return True
616 return False
616 return False
617
617
618 def tsttest(test, wd, options, replacements):
618 def tsttest(test, wd, options, replacements, env):
619 # We generate a shell script which outputs unique markers to line
619 # We generate a shell script which outputs unique markers to line
620 # up script results with our source. These markers include input
620 # up script results with our source. These markers include input
621 # line number and the last return code
621 # line number and the last return code
@@ -741,7 +741,7 b' def tsttest(test, wd, options, replaceme'
741
741
742 cmd = '%s "%s"' % (options.shell, name)
742 cmd = '%s "%s"' % (options.shell, name)
743 vlog("# Running", cmd)
743 vlog("# Running", cmd)
744 exitcode, output = run(cmd, wd, options, replacements)
744 exitcode, output = run(cmd, wd, options, replacements, env)
745 # do not merge output if skipped, return hghave message instead
745 # do not merge output if skipped, return hghave message instead
746 # similarly, with --debug, output is None
746 # similarly, with --debug, output is None
747 if exitcode == SKIPPED_STATUS or output is None:
747 if exitcode == SKIPPED_STATUS or output is None:
@@ -791,16 +791,16 b' def tsttest(test, wd, options, replaceme'
791 return exitcode, postout
791 return exitcode, postout
792
792
793 wifexited = getattr(os, "WIFEXITED", lambda x: False)
793 wifexited = getattr(os, "WIFEXITED", lambda x: False)
794 def run(cmd, wd, options, replacements):
794 def run(cmd, wd, options, replacements, env):
795 """Run command in a sub-process, capturing the output (stdout and stderr).
795 """Run command in a sub-process, capturing the output (stdout and stderr).
796 Return a tuple (exitcode, output). output is None in debug mode."""
796 Return a tuple (exitcode, output). output is None in debug mode."""
797 # TODO: Use subprocess.Popen if we're running on Python 2.4
797 # TODO: Use subprocess.Popen if we're running on Python 2.4
798 if options.debug:
798 if options.debug:
799 proc = subprocess.Popen(cmd, shell=True, cwd=wd)
799 proc = subprocess.Popen(cmd, shell=True, cwd=wd, env=env)
800 ret = proc.wait()
800 ret = proc.wait()
801 return (ret, None)
801 return (ret, None)
802
802
803 proc = Popen4(cmd, wd, options.timeout)
803 proc = Popen4(cmd, wd, options.timeout, env)
804 def cleanup():
804 def cleanup():
805 terminate(proc)
805 terminate(proc)
806 ret = proc.wait()
806 ret = proc.wait()
@@ -930,9 +930,11 b' def runone(options, test):'
930 else:
930 else:
931 replacements.append((re.escape(testtmp), '$TESTTMP'))
931 replacements.append((re.escape(testtmp), '$TESTTMP'))
932
932
933 env = os.environ.copy()
934
933 if options.time:
935 if options.time:
934 starttime = time.time()
936 starttime = time.time()
935 ret, out = runner(testpath, testtmp, options, replacements)
937 ret, out = runner(testpath, testtmp, options, replacements, env)
936 if options.time:
938 if options.time:
937 endtime = time.time()
939 endtime = time.time()
938 times.append((test, endtime - starttime))
940 times.append((test, endtime - starttime))
General Comments 0
You need to be logged in to leave comments. Login now