Example #1
0
def test_subprocess_popen_environ_cleanup(envvar, meipass):
    with PatchedEnviron(**{envvar: meipass}):
        original_env = dict(os.environ)
        assert envvar in original_env
        instance = overrides.PyinstallerPopen(
            [
                sys.executable,
                "-c",
                "import os, json; print(json.dumps(dict(os.environ)))",
            ],
            stdout=subprocess.PIPE,
            universal_newlines=True,
        )
        stdout, _ = instance.communicate()
        assert instance.returncode == 0
        returned_env = json.loads(stdout)
        assert returned_env != original_env
        assert envvar in returned_env
        assert returned_env[envvar] == ""
Example #2
0
def test_subprocess_popen_environ_cleanup_passed_directly_not_removed(
        envvar, meipass):
    env = {
        envvar: meipass,
    }
    original_env = dict(os.environ)

    instance = overrides.PyinstallerPopen(
        [
            sys.executable, "-c",
            "import os, json; print(json.dumps(dict(os.environ)))"
        ],
        env=env.copy(),
        stdout=subprocess.PIPE,
        universal_newlines=True,
    )
    stdout, _ = instance.communicate()
    assert instance.returncode == 0
    returned_env = json.loads(stdout)
    assert returned_env != original_env
    assert envvar in returned_env
    assert returned_env[envvar] == meipass