Skip to content

Commit 7ab249b

Browse files
maxkoryukovtheskumar
authored andcommitted
Disable ".env not found" warning by default (theskumar#57)
* Disable ".env not found" warning by default * Mention VERBOSE option in readme * Fix tests for `load_dotenv` with new verbose option
1 parent 5e839d4 commit 7ab249b

3 files changed

Lines changed: 7 additions & 3 deletions

File tree

README.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ Add the following code to your ``settings.py``
4949
dotenv_path = join(dirname(__file__), '.env')
5050
load_dotenv(dotenv_path)
5151
52+
# OR, the same with increased verbosity:
53+
load_dotenv(dotenv_path, verbose=True)
54+
5255
Alternatively, you can use ``find_dotenv()`` method that will try to find a
5356
``.env`` file by (a) guessing where to start using ``__file__`` or the working
5457
directory -- allowing this to work in non-file contexts such as IPython notebooks

dotenv/main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ def decode_escaped(escaped):
1616
return __escape_decoder(escaped)[0]
1717

1818

19-
def load_dotenv(dotenv_path):
19+
def load_dotenv(dotenv_path, verbose=False):
2020
"""
2121
Read a .env file and load into os.environ.
2222
"""
2323
if not os.path.exists(dotenv_path):
24-
warnings.warn("Not loading %s - it doesn't exist." % dotenv_path)
24+
if verbose:
25+
warnings.warn("Not loading %s - it doesn't exist." % dotenv_path)
2526
return None
2627
for k, v in dotenv_values(dotenv_path).items():
2728
os.environ.setdefault(k, v)

tests/test_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
def test_warns_if_file_does_not_exist():
1212
with warnings.catch_warnings(record=True) as w:
13-
load_dotenv('.does_not_exist')
13+
load_dotenv('.does_not_exist', verbose=True)
1414

1515
assert len(w) == 1
1616
assert w[0].category is UserWarning

0 commit comments

Comments
 (0)