diff --git a/pyccc/engines/subproc.py b/pyccc/engines/subproc.py index 4ff6707..69861b2 100644 --- a/pyccc/engines/subproc.py +++ b/pyccc/engines/subproc.py @@ -64,12 +64,14 @@ def submit(self, job): for filename, f in job.inputs.items(): f.put(os.path.join(job.workingdir, filename)) + subenv = os.environ.copy() + subenv['PYTHONIOENCODING'] = 'utf-8' job.subproc = subprocess.Popen(job.command, shell=True, cwd=job.workingdir, stdout=subprocess.PIPE, stderr=subprocess.PIPE, - env={'PYTHONIOENCODING': 'utf-8'}) + env=subenv) job.jobid = job.subproc.pid job._started = True return job.subproc.pid diff --git a/pyccc/tests/test_job_types.py b/pyccc/tests/test_job_types.py index b7717e6..e8f0534 100644 --- a/pyccc/tests/test_job_types.py +++ b/pyccc/tests/test_job_types.py @@ -174,6 +174,21 @@ def test_bash_exitcode(fixture, request): assert job.exitcode == 35 +@pytest.fixture +def set_env_var(): + import os + assert 'NULL123' not in os.environ, "Bleeding environment" + os.environ['NULL123'] = 'nullabc' + yield + del os.environ['NULL123'] + + +def test_subprocess_environment_preserved(subprocess_engine, set_env_var): + job = subprocess_engine.launch(command='echo $NULL123', image='python:2.7-slim') + job.wait() + assert job.stdout.strip() == 'nullabc' + + @pytest.mark.parametrize('fixture', fixture_types['engine']) def test_python_exitcode(fixture, request): engine = request.getfuncargvalue(fixture)