Preserve any existing PYTHONPATH in tests

This commit is contained in:
Lumir Balhar 2021-06-22 22:10:17 +02:00 committed by su-fang
parent 42189e3087
commit fddd690a58
1 changed files with 8 additions and 2 deletions

View File

@ -101,9 +101,15 @@ def dev_server(xprocess, request, tmp_path):
class Starter(ProcessStarter):
args = [sys.executable, run_path, name, json.dumps(kwargs)]
# Extend the existing env, otherwise Windows and CI fails.
# Modules will be imported from tmp_path for the reloader.
# Modules will be imported from tmp_path for the reloader
# but any existing PYTHONPATH is preserved.
# Unbuffered output so the logs update immediately.
env = {**os.environ, "PYTHONPATH": str(tmp_path), "PYTHONUNBUFFERED": "1"}
original_python_path = os.getenv("PYTHONPATH")
if original_python_path:
new_python_path = os.pathsep.join((original_python_path, str(tmp_path)))
else:
new_python_path = str(tmp_path)
env = {**os.environ, "PYTHONPATH": new_python_path, "PYTHONUNBUFFERED": "1"}
@cached_property
def pattern(self):