@@ -497,7 +497,7 @@ def consider_pluginarg(self, arg):
497497 if not name .startswith ("pytest_" ):
498498 self .set_blocked ("pytest_" + name )
499499 else :
500- self .import_plugin (arg )
500+ self .import_plugin (arg , consider_entry_points = True )
501501
502502 def consider_conftest (self , conftestmodule ):
503503 self .register (conftestmodule , name = conftestmodule .__file__ )
@@ -513,7 +513,11 @@ def _import_plugin_specs(self, spec):
513513 for import_spec in plugins :
514514 self .import_plugin (import_spec )
515515
516- def import_plugin (self , modname ):
516+ def import_plugin (self , modname , consider_entry_points = False ):
517+ """
518+ Imports a plugin with ``modname``. If ``consider_entry_points`` is True, entry point
519+ names are also considered to find a plugin.
520+ """
517521 # most often modname refers to builtin modules, e.g. "pytester",
518522 # "terminal" or "capture". Those plugins are registered under their
519523 # basename for historic purposes but must be imported with the
@@ -524,22 +528,26 @@ def import_plugin(self, modname):
524528 modname = str (modname )
525529 if self .is_blocked (modname ) or self .get_plugin (modname ) is not None :
526530 return
527- if modname in builtin_plugins :
528- importspec = "_pytest." + modname
529- else :
530- importspec = modname
531+
532+ importspec = "_pytest." + modname if modname in builtin_plugins else modname
531533 self .rewrite_hook .mark_rewrite (importspec )
534+
535+ if consider_entry_points :
536+ loaded = self .load_setuptools_entrypoints ("pytest11" , name = modname )
537+ if loaded :
538+ return
539+
532540 try :
533541 __import__ (importspec )
534542 except ImportError as e :
535- new_exc_type = ImportError
536543 new_exc_message = 'Error importing plugin "%s": %s' % (
537544 modname ,
538545 safe_str (e .args [0 ]),
539546 )
540- new_exc = new_exc_type (new_exc_message )
547+ new_exc = ImportError (new_exc_message )
548+ tb = sys .exc_info ()[2 ]
541549
542- six .reraise (new_exc_type , new_exc , sys . exc_info ()[ 2 ] )
550+ six .reraise (ImportError , new_exc , tb )
543551
544552 except Skipped as e :
545553 from _pytest .warnings import _issue_warning_captured
0 commit comments