comparison tests/run-tests.py @ 33203:cf826b9e9ea4

tests: actually restore the original environment before running syshg Since os.environ may be overridden in run-tests.py, several important variables such as PATH weren't restored. I don't like the idea of using the system hg *by default* because the executable and the configs are out of our control. But I don't mind as long as the tests pass.
author Yuya Nishihara <yuya@tcha.org>
date Fri, 30 Jun 2017 21:49:29 +0900
parents f458a6701983
children e80041832eec
comparison
equal deleted inserted replaced
33200:04cf9927f350 33203:cf826b9e9ea4
82 reload(sys) 82 reload(sys)
83 sys.setdefaultencoding("undefined") 83 sys.setdefaultencoding("undefined")
84 except NameError: 84 except NameError:
85 pass 85 pass
86 86
87 origenviron = os.environ.copy()
87 osenvironb = getattr(os, 'environb', os.environ) 88 osenvironb = getattr(os, 'environb', os.environ)
88 processlock = threading.Lock() 89 processlock = threading.Lock()
89 90
90 if sys.version_info > (3, 5, 0): 91 if sys.version_info > (3, 5, 0):
91 PYTHON3 = True 92 PYTHON3 = True
905 906
906 # Only restore environment variable names that the shell allows 907 # Only restore environment variable names that the shell allows
907 # us to export. 908 # us to export.
908 name_regex = re.compile('^[a-zA-Z][a-zA-Z0-9_]*$') 909 name_regex = re.compile('^[a-zA-Z][a-zA-Z0-9_]*$')
909 910
911 # Do not restore these variables; otherwise tests would fail.
912 reqnames = {'PYTHON', 'TESTDIR', 'TESTTMP'}
913
910 with open(scriptpath, 'w') as envf: 914 with open(scriptpath, 'w') as envf:
911 for name, value in os.environ.items(): 915 for name, value in origenviron.items():
912 if not name_regex.match(name): 916 if not name_regex.match(name):
913 # Skip environment variables with unusual names not 917 # Skip environment variables with unusual names not
914 # allowed by most shells. 918 # allowed by most shells.
915 continue 919 continue
920 if name in reqnames:
921 continue
916 envf.write('%s=%s\n' % (name, shellquote(value))) 922 envf.write('%s=%s\n' % (name, shellquote(value)))
917 923
918 for name in testenv: 924 for name in testenv:
919 if name in os.environ: 925 if name in origenviron or name in reqnames:
920 continue 926 continue
921 envf.write('unset %s\n' % (name,)) 927 envf.write('unset %s\n' % (name,))
922 928
923 def _getenv(self): 929 def _getenv(self):
924 """Obtain environment variables to use during test execution.""" 930 """Obtain environment variables to use during test execution."""