mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-11 15:24:18 +00:00
Merge pull request #1499 from asottile/fix-catastrophic-failure
fix AttributeError when catatstrophic failure is triggered
This commit is contained in:
commit
df64e392f4
2 changed files with 19 additions and 6 deletions
|
|
@ -115,11 +115,13 @@ class Application:
|
||||||
|
|
||||||
def exit_code(self) -> int:
|
def exit_code(self) -> int:
|
||||||
"""Return the program exit code."""
|
"""Return the program exit code."""
|
||||||
|
if self.catastrophic_failure:
|
||||||
|
return 1
|
||||||
assert self.options is not None
|
assert self.options is not None
|
||||||
if self.options.exit_zero:
|
if self.options.exit_zero:
|
||||||
return int(self.catastrophic_failure)
|
return 0
|
||||||
else:
|
else:
|
||||||
return int((self.result_count > 0) or self.catastrophic_failure)
|
return int(self.result_count > 0)
|
||||||
|
|
||||||
def find_plugins(
|
def find_plugins(
|
||||||
self,
|
self,
|
||||||
|
|
@ -391,7 +393,7 @@ class Application:
|
||||||
except exceptions.EarlyQuit:
|
except exceptions.EarlyQuit:
|
||||||
self.catastrophic_failure = True
|
self.catastrophic_failure = True
|
||||||
print("... stopped while processing files")
|
print("... stopped while processing files")
|
||||||
|
else:
|
||||||
assert self.options is not None
|
assert self.options is not None
|
||||||
if self.options.count:
|
if self.options.count:
|
||||||
print(self.result_count)
|
print(self.result_count)
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import pytest
|
||||||
|
|
||||||
from flake8 import utils
|
from flake8 import utils
|
||||||
from flake8.main import cli
|
from flake8.main import cli
|
||||||
|
from flake8.options import config
|
||||||
|
|
||||||
|
|
||||||
def test_diff_option(tmpdir, capsys):
|
def test_diff_option(tmpdir, capsys):
|
||||||
|
|
@ -375,3 +376,13 @@ def test_output_file(tmpdir, capsys):
|
||||||
|
|
||||||
expected = "t.py:1:1: F401 'os' imported but unused\n"
|
expected = "t.py:1:1: F401 'os' imported but unused\n"
|
||||||
assert tmpdir.join("a/b/f").read() == expected
|
assert tmpdir.join("a/b/f").read() == expected
|
||||||
|
|
||||||
|
|
||||||
|
def test_early_keyboard_interrupt_does_not_crash(capsys):
|
||||||
|
with mock.patch.object(
|
||||||
|
config, "load_config", side_effect=KeyboardInterrupt
|
||||||
|
):
|
||||||
|
assert cli.main(["does-not-exist"]) == 1
|
||||||
|
out, err = capsys.readouterr()
|
||||||
|
assert out == "... stopped\n"
|
||||||
|
assert err == ""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue