def test_load_dot_env_warns_if_file_doesnt_exist(capsys): with temp_environ(), TemporaryDirectory(prefix='pipenv-', suffix='') as tempdir: dotenv_path = os.path.join(tempdir.name, 'does-not-exist.env') with mock.patch('pipenv.environments.PIPENV_DOTENV_LOCATION', dotenv_path): load_dot_env() output, err = capsys.readouterr() assert 'Warning' in err
def test_load_dot_env_warns_if_file_doesnt_exist(monkeypatch, capsys, project): with temp_environ(), monkeypatch.context() as m, TemporaryDirectory(prefix='pipenv-', suffix='') as tempdir: if os.name == "nt": import click is_console = False m.setattr(click._winconsole, "_is_console", lambda x: is_console) dotenv_path = os.path.join(tempdir, 'does-not-exist.env') project.s.PIPENV_DOTENV_LOCATION = str(dotenv_path) load_dot_env(project) output, err = capsys.readouterr() assert 'Warning' in err
def test_load_dot_env_from_environment_variable_location(capsys): with temp_environ(), TemporaryDirectory(prefix='pipenv-', suffix='') as tempdir: dotenv_path = os.path.join(tempdir.name, 'test.env') key, val = 'SOME_KEY', 'some_value' with open(dotenv_path, 'w') as f: f.write('{}={}'.format(key, val)) with mock.patch('pipenv.environments.PIPENV_DOTENV_LOCATION', dotenv_path): load_dot_env() assert os.environ[key] == val
def test_load_dot_env_from_environment_variable_location(monkeypatch, capsys, project): with temp_environ(), monkeypatch.context() as m, TemporaryDirectory(prefix='pipenv-', suffix='') as tempdir: if os.name == "nt": import click is_console = False m.setattr(click._winconsole, "_is_console", lambda x: is_console) dotenv_path = os.path.join(tempdir, 'test.env') key, val = 'SOME_KEY', 'some_value' with open(dotenv_path, 'w') as f: f.write(f'{key}={val}') project.s.PIPENV_DOTENV_LOCATION = str(dotenv_path) load_dot_env(project) assert os.environ[key] == val
def test_doesnt_load_dot_env_if_disabled(capsys): with temp_environ(), TemporaryDirectory(prefix='pipenv-', suffix='') as tempdir: dotenv_path = os.path.join(tempdir.name, 'test.env') key, val = 'SOME_KEY', 'some_value' with open(dotenv_path, 'w') as f: f.write('{}={}'.format(key, val)) with mock.patch('pipenv.environments.PIPENV_DOTENV_LOCATION', dotenv_path): with mock.patch('pipenv.environments.PIPENV_DONT_LOAD_ENV', '1'): load_dot_env() assert key not in os.environ load_dot_env() assert key in os.environ
def test_doesnt_load_dot_env_if_disabled(monkeypatch, capsys, project): with temp_environ(), monkeypatch.context() as m, TemporaryDirectory( prefix='pipenv-', suffix='') as tempdir: if os.name == "nt": import click is_console = False m.setattr(click._winconsole, "_is_console", lambda x: is_console) dotenv_path = os.path.join(tempdir.name, 'test.env') key, val = 'SOME_KEY', 'some_value' with open(dotenv_path, 'w') as f: f.write(f'{key}={val}') project.s.PIPENV_DOTENV_LOCATION = str(dotenv_path) project.s.PIPENV_DONT_LOAD_ENV = True load_dot_env(project) assert key not in os.environ project.s.PIPENV_DONT_LOAD_ENV = False load_dot_env(project) assert key in os.environ
def test_doesnt_load_dot_env_if_disabled(monkeypatch, capsys): with temp_environ(), monkeypatch.context() as m, TemporaryDirectory( prefix='pipenv-', suffix='') as tempdir: if os.name == "nt": import click is_console = False m.setattr(click._winconsole, "_is_console", lambda x: is_console) dotenv_path = os.path.join(tempdir.name, 'test.env') key, val = 'SOME_KEY', 'some_value' with open(dotenv_path, 'w') as f: f.write('{}={}'.format(key, val)) m.setenv("PIPENV_DOTENV_LOCATION", str(dotenv_path)) m.setattr("pipenv.environments.PIPENV_DOTENV_LOCATION", str(dotenv_path)) m.setattr("pipenv.environments.PIPENV_DONT_LOAD_ENV", True) load_dot_env() assert key not in os.environ m.setattr("pipenv.environments.PIPENV_DONT_LOAD_ENV", False) load_dot_env() assert key in os.environ