@@ -518,6 +518,8 @@ def import_plugin(self, modname):
518518 assert isinstance (modname , six .string_types ), (
519519 "module name as text required, got %r" % modname
520520 )
521+ from pkg_resources import iter_entry_points , DistributionNotFound
522+
521523 modname = str (modname )
522524 if self .is_blocked (modname ) or self .get_plugin (modname ) is not None :
523525 return
@@ -526,29 +528,40 @@ def import_plugin(self, modname):
526528 else :
527529 importspec = modname
528530 self .rewrite_hook .mark_rewrite (importspec )
529- try :
530- __import__ (importspec )
531- except ImportError as e :
532- new_exc_type = ImportError
533- new_exc_message = 'Error importing plugin "%s": %s' % (
534- modname ,
535- safe_str (e .args [0 ]),
536- )
537- new_exc = new_exc_type (new_exc_message )
531+ mod = None
532+ # TODO: this needs to be moved to pluggy so it can update its _plugin_distinfo attribute
533+ eps = list (iter_entry_points ("pytest11" , modname ))
534+ if eps :
535+ try :
536+ mod = eps [0 ].load ()
537+ except DistributionNotFound :
538+ pass
539+ else :
540+ try :
541+ __import__ (importspec )
542+ mod = sys .modules [importspec ]
543+ except ImportError as e :
544+ new_exc_message = 'Error importing plugin "%s": %s' % (
545+ modname ,
546+ safe_str (e .args [0 ]),
547+ )
548+ new_exc = ImportError (new_exc_message )
549+ tb = sys .exc_info ()[2 ]
538550
539- six .reraise (new_exc_type , new_exc , sys . exc_info ()[ 2 ] )
551+ six .reraise (ImportError , new_exc , tb )
540552
541- except Skipped as e :
542- from _pytest .warnings import _issue_warning_captured
553+ except Skipped as e :
554+ from _pytest .warnings import _issue_warning_captured
543555
544- _issue_warning_captured (
545- PytestWarning ("skipped plugin %r: %s" % (modname , e .msg )),
546- self .hook ,
547- stacklevel = 1 ,
548- )
549- else :
550- mod = sys .modules [importspec ]
551- self .register (mod , modname )
556+ _issue_warning_captured (
557+ PytestWarning ("skipped plugin %r: %s" % (modname , e .msg )),
558+ self .hook ,
559+ stacklevel = 1 ,
560+ )
561+ return
562+
563+ assert mod is not None
564+ self .register (mod , modname )
552565
553566
554567def _get_plugin_specs_as_list (specs ):
0 commit comments