Skip to content

Commit 1312397

Browse files
Fix: Use FileNotFoundError for file not found in main.py
Replaced IOError with FileNotFoundError on line 377 of main.py to use a more specific and appropriate exception for file not found errors. test: update test_find_dotenv_no_file_raise to expect FileNotFoundError Updated test_main.py (line 351) to replace IOError with FileNotFoundError so that the test matches the updated exception handling in main.py.
1 parent d6e219d commit 1312397

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

tests/test_main.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ def test_get_key_no_file(tmp_path):
178178
assert result is None
179179
mock_info.assert_has_calls(
180180
calls=[
181-
mock.call("python-dotenv could not find configuration file %s.", nx_path)
181+
mock.call(
182+
"python-dotenv could not find configuration file %s.", nx_path)
182183
],
183184
)
184185
mock_warning.assert_has_calls(
@@ -193,7 +194,8 @@ def test_get_key_not_found(dotenv_path):
193194
result = dotenv.get_key(dotenv_path, "foo")
194195

195196
assert result is None
196-
mock_warning.assert_called_once_with("Key %s not found in %s.", "foo", dotenv_path)
197+
mock_warning.assert_called_once_with(
198+
"Key %s not found in %s.", "foo", dotenv_path)
197199

198200

199201
def test_get_key_ok(dotenv_path):
@@ -346,7 +348,7 @@ def test_find_dotenv_no_file_raise(tmp_path):
346348
leaf = prepare_file_hierarchy(tmp_path)
347349
os.chdir(leaf)
348350

349-
with pytest.raises(IOError):
351+
with pytest.raises(FileNotFoundError):
350352
dotenv.find_dotenv(raise_error_if_not_found=True, usecwd=True)
351353

352354

0 commit comments

Comments
 (0)