Commit f9a78f97 authored by Kirill Smelkov's avatar Kirill Smelkov

Allow TestCase to only adjust environment, instead of fully redefining it

It is frequently needed to set some environment variable without
completely resetting everything else in the environment, because that
everything else can carry settings like PATH, PYTHONPATH, RPATH, etc for
the program to be able to run at all.

See pygolang@b938af8b for recent example.
parent ab430f46
......@@ -35,7 +35,7 @@ For example the following .nxdtest defines 3 test cases that run Wendelin.core
for stor in ['fs1', 'zeo', 'neo']:
TestCase('test.py/%s' % stor, ['make', 'test.py'],
env={'WENDELIN_CORE_TEST_DB': '<%s>' % stor,
envadj={'WENDELIN_CORE_TEST_DB': '<%s>' % stor,
summaryf=PyTest.summary)
Nxdtest only runs tests, but - unlike tox - does not prepare variants of
......@@ -142,9 +142,16 @@ def main():
try:
# Run t.argv in t.kw['env'] environment.
# In addition to kw['env'], kw['envadj'] allows users to define
# only adjustments instead of providing full env dict.
# Test command is spawned with unchanged cwd. Instance wrapper cares to set cwd before running us.
# bufsize=1 means 'line buffered'
p = Popen(t.argv, stdin=devnull, stdout=PIPE, stderr=PIPE, bufsize=1, **t.kw)
kw = t.kw.copy()
env = kw.pop('env', os.environ)
env = env.copy()
envadj = kw.pop('envadj', {})
env.update(envadj)
p = Popen(t.argv, env=env, stdin=devnull, stdout=PIPE, stderr=PIPE, bufsize=1, **kw)
except:
stdout, stderr = '', traceback.format_exc()
sys.stderr.write(stderr)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment