mirror of
https://github.com/PyCQA/flake8.git
synced 2026-03-29 02:26:54 +00:00
Merge pull request #1498 from rkm/fix-missing-config
return an error if the explicitly specified config is missing
This commit is contained in:
commit
38c5eceda9
3 changed files with 29 additions and 1 deletions
|
|
@ -8,6 +8,7 @@ from typing import List
|
|||
from typing import Optional
|
||||
from typing import Tuple
|
||||
|
||||
from flake8 import exceptions
|
||||
from flake8.options.manager import OptionManager
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
|
@ -60,7 +61,10 @@ def load_config(
|
|||
|
||||
cfg = configparser.RawConfigParser()
|
||||
if config is not None:
|
||||
cfg.read(config)
|
||||
if not cfg.read(config):
|
||||
raise exceptions.ExecutionError(
|
||||
f"The specified config file does not exist: {config}"
|
||||
)
|
||||
cfg_dir = os.path.dirname(config)
|
||||
else:
|
||||
cfg_dir = pwd
|
||||
|
|
|
|||
|
|
@ -386,3 +386,21 @@ def test_early_keyboard_interrupt_does_not_crash(capsys):
|
|||
out, err = capsys.readouterr()
|
||||
assert out == "... stopped\n"
|
||||
assert err == ""
|
||||
|
||||
|
||||
def test_config_file_not_found(tmpdir, capsys):
|
||||
"""Ensure that an explicitly specified config file which is not found is an
|
||||
error"""
|
||||
|
||||
expected = """\
|
||||
There was a critical error during execution of Flake8:
|
||||
The specified config file does not exist: missing.cfg
|
||||
"""
|
||||
|
||||
with tmpdir.as_cwd():
|
||||
tmpdir.join("t.py").write("print('hello hello world')\n")
|
||||
assert cli.main(["--config", "missing.cfg", "t.py"]) == 1
|
||||
|
||||
out, err = capsys.readouterr()
|
||||
assert out == expected
|
||||
assert err == ""
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import configparser
|
|||
|
||||
import pytest
|
||||
|
||||
from flake8 import exceptions
|
||||
from flake8.main.options import register_default_options
|
||||
from flake8.options import config
|
||||
from flake8.options.manager import OptionManager
|
||||
|
|
@ -164,3 +165,8 @@ def test_parse_config_ignores_unknowns(tmp_path, opt_manager, caplog):
|
|||
'Option "wat" is not registered. Ignoring.',
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
def test_load_config_missing_file_raises_exception(capsys):
|
||||
with pytest.raises(exceptions.ExecutionError):
|
||||
config.load_config("foo.cfg", [])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue