diff --git a/src/dotenv/main.py b/src/dotenv/main.py index 98b22ec0..b4d3a544 100644 --- a/src/dotenv/main.py +++ b/src/dotenv/main.py @@ -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)) diff --git a/tests/test_core.py b/tests/test_core.py index c366cb34..eed46f97 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -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')