Skip to content

Commit

Permalink
Suppressing .env loading message when PIPENV_QUIET is set
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-septeo committed Feb 15, 2019
1 parent 44db5dd commit 9f04c93
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
1 change: 1 addition & 0 deletions news/2358.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Suppress .env loading message when PIPENV_QUIET is set
9 changes: 5 additions & 4 deletions pipenv/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,11 @@ def load_dot_env():
)

if os.path.isfile(dotenv_file):
click.echo(
crayons.normal(fix_utf8("Loading .env environment variables…"), bold=True),
err=True,
)
if not environments.is_quiet():
click.echo(
crayons.normal(fix_utf8("Loading .env environment variables…"), bold=True),
err=True,
)
else:
if environments.PIPENV_DOTENV_LOCATION:
click.echo(
Expand Down
31 changes: 31 additions & 0 deletions tests/unit/test_core.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- coding=utf-8 -*-

import os

import mock
Expand Down Expand Up @@ -57,3 +59,32 @@ def test_load_dot_env_warns_if_file_doesnt_exist(capsys):
load_dot_env()
output, err = capsys.readouterr()
assert 'Warning' in err


@pytest.mark.core
def test_load_dot_env_quiet(capsys):
# Setting PIPENV_QUIET in environment will suppress the .env loading message
message = 'Loading .env environment variables'

with temp_environ(), TemporaryDirectory(prefix='pipenv-', suffix='') as tempdir:
dotenv_path = os.path.join(tempdir.name, 'test.env')
with open(dotenv_path, 'w'):
pass

with mock.patch('pipenv.environments.PIPENV_DOTENV_LOCATION', dotenv_path):
load_dot_env()

output, err = capsys.readouterr()
assert message in err

with mock.patch('pipenv.environments.PIPENV_VERBOSITY', -1):
load_dot_env()

output, err = capsys.readouterr()
assert message not in err

with mock.patch('pipenv.environments.PIPENV_VERBOSITY', 1):
load_dot_env()

output, err = capsys.readouterr()
assert message in err

0 comments on commit 9f04c93

Please sign in to comment.