Merge branch 'error-when-duplicate-entry-points' into 'master'

Emit an error when entry points are duplicated

Closes #634

See merge request pycqa/flake8!425
This commit is contained in:
Peter Law 2021-03-16 03:09:52 +00:00
commit afcb7d8d24
6 changed files with 71 additions and 4 deletions

View file

@ -0,0 +1,4 @@
[flake8:local-plugins]
extension =
XE = aplugin:ExtensionTestPluginA
XE = aplugin:ExtensionTestPluginB

View file

@ -1,9 +1,13 @@
"""Integration tests for plugin loading."""
import pytest
from flake8.main import application
from flake8 import exceptions
LOCAL_PLUGIN_CONFIG = 'tests/fixtures/config_files/local-plugin.ini'
LOCAL_PLUGIN_PATH_CONFIG = 'tests/fixtures/config_files/local-plugin-path.ini'
LOCAL_PLUGIN_DUPLICATE_CONFIG = 'tests/fixtures/config_files/local-plugin-duplicate-entry-point.ini'
class ExtensionTestPlugin(object):
@ -61,3 +65,10 @@ def test_enable_local_plugin_at_non_installed_path():
app.initialize(['flake8', '--config', LOCAL_PLUGIN_PATH_CONFIG])
assert app.check_plugins['XE'].plugin.name == 'ExtensionTestPlugin2'
def test_reject_local_plugins_with_duplicate_entry_point():
"""Reject duplicate entry points in local-plugins config section."""
with pytest.raises(exceptions.DuplicatePluginEntryPoint):
app = application.Application()
app.initialize(['flake8', '--config', LOCAL_PLUGIN_DUPLICATE_CONFIG])

View file

@ -48,6 +48,18 @@ def test_exit_does_raise(result_count, catastrophic, exit_zero, value,
assert excinfo.value.args[0] is value
def test_exit_raises(application):
"""Verify Application.exit raises SystemExit under configuration failure."""
application.catastrophic_failure = True
# Note: no application.options set -- configuration issues can lead to
# errors before it's assigned.
with pytest.raises(SystemExit) as excinfo:
application.exit()
assert excinfo.value.args[0] is True
def test_warns_on_unknown_formatter_plugin_name(application):
"""Verify we log a warning with an unfound plugin."""
default = mock.Mock()