From 9f04c93367d184a72f558da66f611e87c267484b Mon Sep 17 00:00:00 2001 From: Michael Lemaire Date: Fri, 15 Feb 2019 12:14:27 +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 | 31 +++++++++++++++++++++++++++++++ 3 files changed, 37 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..0a27013276 100644 --- a/tests/unit/test_core.py +++ b/tests/unit/test_core.py @@ -1,3 +1,5 @@ +# -*- coding=utf-8 -*- + import os import mock @@ -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