diff --git a/src/environs/__init__.py b/src/environs/__init__.py index 0b8ece4..2fb8e40 100644 --- a/src/environs/__init__.py +++ b/src/environs/__init__.py @@ -454,7 +454,7 @@ def read_env( verbose: _BoolType = False, override: _BoolType = False, return_path: _BoolType = False, - ) -> typing.Union[_BoolType, _StrType]: + ) -> typing.Union[_BoolType, typing.Optional[_StrType]]: """Read a .env file into os.environ. If .env is not found in the directory from which this method is called, @@ -462,8 +462,7 @@ def read_env( file is found. If you do not wish to recurse up the tree, you may pass False as a second positional argument. """ - - env_path = "" + env_path = None is_env_loaded = False if path is None: # By default, start search from the same directory this function is called diff --git a/tests/test_environs.py b/tests/test_environs.py index 0c6cd49..20ba78a 100644 --- a/tests/test_environs.py +++ b/tests/test_environs.py @@ -426,17 +426,14 @@ def test_read_env_return_path_if_env_not_found(self, env, tmp_path): # Move .env file to temp location env_path = HERE / ".env" temp_env = tmp_path / ".env" - env_path.rename(temp_env) - try: + env_path.rename(temp_env) path = env.read_env(return_path=True) + assert path is None finally: # Restore .env file if temp_env.exists(): temp_env.rename(env_path) - assert path == "" - - assert path == "" def always_fail(value):