Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion dotenv/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,11 @@ def find_dotenv(filename='.env', raise_error_if_not_found=False, usecwd=False):
path = os.getcwd()
else:
# will work for .py files
frame_filename = sys._getframe().f_back.f_code.co_filename
frame = sys._getframe()
# find first frame that is outside of this file
while frame.f_code.co_filename == __file__:
frame = frame.f_back
frame_filename = frame.f_code.co_filename
path = os.path.dirname(os.path.abspath(frame_filename))

for dirname in _walk_to_root(path):
Expand Down
15 changes: 14 additions & 1 deletion tests/test_core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf8 -*-
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import os
Expand Down Expand Up @@ -107,6 +107,19 @@ def test_load_dotenv_override(cli):
sh.rm(dotenv_path)


def test_load_dotenv_in_current_dir():
# make sure were are here!
os.chdir(os.path.dirname(os.path.realpath(__file__)))
dotenv_path = '.env'
with open(dotenv_path, 'w') as f:
f.write("TOTO=bla\n")
assert 'TOTO' not in os.environ
success = load_dotenv(verbose=True)
assert success
assert os.environ['TOTO'] == 'bla'
sh.rm(dotenv_path)


def test_ipython():
tmpdir = os.path.realpath(tempfile.mkdtemp())
os.chdir(tmpdir)
Expand Down