Write a test checking plugin failure exception handling

This commit is contained in:
Tomer Keren 2019-01-13 21:24:44 +02:00 committed by Anthony Sottile
parent c68e7a8d3e
commit b64421c5e8
2 changed files with 35 additions and 0 deletions

View file

@ -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)