mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-07 05:26:53 +00:00
Make Plugin.load_plugin raise a Flake8 exception
Let's catch exceptions, log them, and re-raise as a FailedToLoad exception. This also refactors the actually loading of plugins into a private method on the Plugin class.
This commit is contained in:
parent
6546cf41d4
commit
3b64ff2a1f
3 changed files with 62 additions and 12 deletions
|
|
@ -1,6 +1,8 @@
|
|||
"""Tests for flake8.plugins.manager.Plugin."""
|
||||
import mock
|
||||
import pytest
|
||||
|
||||
from flake8 import exceptions
|
||||
from flake8.plugins import manager
|
||||
|
||||
|
||||
|
|
@ -48,6 +50,16 @@ def test_load_plugin_only_calls_require_when_verifying_requirements():
|
|||
entry_point.resolve.assert_called_once_with()
|
||||
|
||||
|
||||
def test_load_plugin_catches_and_reraises_exceptions():
|
||||
"""Verify we raise our own FailedToLoadPlugin."""
|
||||
entry_point = mock.Mock(spec=['require', 'resolve'])
|
||||
entry_point.resolve.side_effect = ValueError('Test failure')
|
||||
plugin = manager.Plugin('T000', entry_point)
|
||||
|
||||
with pytest.raises(exceptions.FailedToLoadPlugin):
|
||||
plugin.load_plugin()
|
||||
|
||||
|
||||
def test_plugin_property_loads_plugin_on_first_use():
|
||||
"""Verify that we load our plugin when we first try to use it."""
|
||||
entry_point = mock.Mock(spec=['require', 'resolve', 'load'])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue