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 0637c2259d..6eaf5b4306 100644 --- a/pipenv/core.py +++ b/pipenv/core.py @@ -147,10 +147,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