mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-03 11:56:52 +00:00
Write a test checking plugin failure exception handling
This commit is contained in:
parent
c68e7a8d3e
commit
b64421c5e8
2 changed files with 35 additions and 0 deletions
17
tests/unit/conftest.py
Normal file
17
tests/unit/conftest.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
"""Shared fixtures between unit tests"""
|
||||
import pytest
|
||||
import optparse
|
||||
|
||||
def options_from(**kwargs):
|
||||
"""Generate a Values instances with our kwargs."""
|
||||
kwargs.setdefault('hang_closing', True)
|
||||
kwargs.setdefault('max_line_length', 79)
|
||||
kwargs.setdefault('verbose', False)
|
||||
kwargs.setdefault('stdin_display_name', 'stdin')
|
||||
return optparse.Values(kwargs)
|
||||
|
||||
@pytest.fixture
|
||||
def default_options():
|
||||
"""Fixture returning the default options of flake8"""
|
||||
return options_from()
|
||||
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
"""Unit tests for the FileChecker class."""
|
||||
import mock
|
||||
import pytest
|
||||
import flake8
|
||||
|
||||
from flake8 import checker
|
||||
|
||||
|
|
@ -43,3 +45,19 @@ def test_nonexistent_file():
|
|||
assert len(c.results) == 1
|
||||
error = c.results[0]
|
||||
assert error[0] == "E902"
|
||||
|
||||
|
||||
def test_raises_proper_exception_on_failed_plugin_run(tmp_path, default_options):
|
||||
foobar = tmp_path / 'foobar.py'
|
||||
foobar.write_text("I exist")
|
||||
plugin = {
|
||||
"name": "failure",
|
||||
"plugin_name": "failure", # Both are necessary
|
||||
"parameters": dict(),
|
||||
"plugin": mock.MagicMock(side_effect=ValueError),
|
||||
}
|
||||
"""Verify a failing plugin results in an plugin error"""
|
||||
fchecker = checker.FileChecker(
|
||||
str(foobar), checks=[], options=default_options)
|
||||
with pytest.raises(flake8.exceptions.PluginExecutionFailed):
|
||||
fchecker.run_check(plugin)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue