@@ -497,7 +497,7 @@ def consider_pluginarg(self, arg):
497
497
if not name .startswith ("pytest_" ):
498
498
self .set_blocked ("pytest_" + name )
499
499
else :
500
- self .import_plugin (arg )
500
+ self .import_plugin (arg , consider_entry_points = True )
501
501
502
502
def consider_conftest (self , conftestmodule ):
503
503
self .register (conftestmodule , name = conftestmodule .__file__ )
@@ -513,7 +513,11 @@ def _import_plugin_specs(self, spec):
513
513
for import_spec in plugins :
514
514
self .import_plugin (import_spec )
515
515
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
+ """
517
521
# most often modname refers to builtin modules, e.g. "pytester",
518
522
# "terminal" or "capture". Those plugins are registered under their
519
523
# basename for historic purposes but must be imported with the
@@ -524,22 +528,26 @@ def import_plugin(self, modname):
524
528
modname = str (modname )
525
529
if self .is_blocked (modname ) or self .get_plugin (modname ) is not None :
526
530
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
531
533
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
+
532
540
try :
533
541
__import__ (importspec )
534
542
except ImportError as e :
535
- new_exc_type = ImportError
536
543
new_exc_message = 'Error importing plugin "%s": %s' % (
537
544
modname ,
538
545
safe_str (e .args [0 ]),
539
546
)
540
- new_exc = new_exc_type (new_exc_message )
547
+ new_exc = ImportError (new_exc_message )
548
+ tb = sys .exc_info ()[2 ]
541
549
542
- six .reraise (new_exc_type , new_exc , sys . exc_info ()[ 2 ] )
550
+ six .reraise (ImportError , new_exc , tb )
543
551
544
552
except Skipped as e :
545
553
from _pytest .warnings import _issue_warning_captured
0 commit comments