diff --git a/conda_subprocess/process.py b/conda_subprocess/process.py index 5981588..960eb3f 100644 --- a/conda_subprocess/process.py +++ b/conda_subprocess/process.py @@ -18,6 +18,7 @@ def Popen( preexec_fn=None, close_fds=True, cwd=None, + env=None, prefix_name=None, prefix_path=None, universal_newlines=None, @@ -52,6 +53,11 @@ def Popen( if not isiterable(command): command = shlex_split_unicode(command) + # update environment + environment_dict = os.environ.copy() + if env is not None: + environment_dict.update(env) + # spawn subprocess return subprocess_Popen( args=encode_arguments(command), @@ -63,7 +69,7 @@ def Popen( close_fds=close_fds, shell=False, cwd=cwd, - env=encode_environment(os.environ.copy()), + env=encode_environment(environment_dict), universal_newlines=universal_newlines, startupinfo=startupinfo, creationflags=creationflags, diff --git a/tests/test_conda_subprocess.py b/tests/test_conda_subprocess.py index f7634ab..d3d9c1a 100644 --- a/tests/test_conda_subprocess.py +++ b/tests/test_conda_subprocess.py @@ -49,3 +49,14 @@ def test_popen(self): else: self.assertEqual(output[0], b"Python 3.12.1\n") self.assertIsNone(output[1]) + + def test_environment_variable(self): + self.assertTrue( + "TESTVAR=test" + in check_output( + "env", + prefix_path=self.env_path, + env={"TESTVAR": "test"}, + universal_newlines=True, + ).split("\n"), + )