From 054ddd2dd404e6d26aaef41afd714c00ba8e878e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Mon, 21 Jan 2019 15:33:46 +0100 Subject: [PATCH] Suppressing .env loading message when PIPENV_QUIET is set --- news/2358.bugfix.rst | 1 + pipenv/core.py | 9 +++++---- tests/unit/test_core.py | 29 +++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 news/2358.bugfix.rst diff --git a/news/2358.bugfix.rst b/news/2358.bugfix.rst new file mode 100644 index 0000000000..5460f81408 --- /dev/null +++ b/news/2358.bugfix.rst @@ -0,0 +1 @@ +Suppress .env loading message when PIPENV_QUIET is set diff --git a/pipenv/core.py b/pipenv/core.py index 934f13b699..95d4e92223 100644 --- a/pipenv/core.py +++ b/pipenv/core.py @@ -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( diff --git a/tests/unit/test_core.py b/tests/unit/test_core.py index 61d318c368..a8cd96e5b9 100644 --- a/tests/unit/test_core.py +++ b/tests/unit/test_core.py @@ -57,3 +57,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