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
9 changes: 8 additions & 1 deletion src/dotenv/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,14 @@ def find_dotenv(filename='.env', raise_error_if_not_found=False, usecwd=False):
# will work for .py files
frame = sys._getframe()
# find first frame that is outside of this file
while frame.f_code.co_filename == __file__:
if PY2 and not __file__.endswith('.py'):
# in Python2 __file__ extension could be .pyc or .pyo (this doesn't account
# for edge case of Python compiled for non-standard extension)
current_file = __file__.rsplit('.', 1)[0] + '.py'
else:
current_file = __file__

while frame.f_code.co_filename == current_file:
frame = frame.f_back
frame_filename = frame.f_code.co_filename
path = os.path.dirname(os.path.abspath(frame_filename))
Expand Down
1 change: 0 additions & 1 deletion tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ def test_load_dotenv_override(tmp_path):
assert os.environ[key_name] == 'WORKS'


@pytest.mark.xfail(sys.version_info < (3, 0), reason="test was incomplete")
def test_load_dotenv_in_current_dir(tmp_path):
dotenv_path = tmp_path / '.env'
dotenv_path.write_bytes(b'a=b')
Expand Down