@@ -286,19 +286,6 @@ def _prepareconfig(
286
286
raise
287
287
288
288
289
- def _fail_on_non_top_pytest_plugins (conftestpath , confcutdir ):
290
- msg = (
291
- "Defining 'pytest_plugins' in a non-top-level conftest is no longer supported:\n "
292
- "It affects the entire test suite instead of just below the conftest as expected.\n "
293
- " {}\n "
294
- "Please move it to a top level conftest file at the rootdir:\n "
295
- " {}\n "
296
- "For more information, visit:\n "
297
- " https://docs.pytest.org/en/latest/deprecations.html#pytest-plugins-in-non-top-level-conftest-files"
298
- )
299
- fail (msg .format (conftestpath , confcutdir ), pytrace = False )
300
-
301
-
302
289
class PytestPluginManager (PluginManager ):
303
290
"""
304
291
Overwrites :py:class:`pluggy.PluginManager <pluggy.PluginManager>` to add pytest-specific
@@ -527,15 +514,11 @@ def _importconftest(self, conftestpath):
527
514
528
515
try :
529
516
mod = conftestpath .pyimport ()
530
- if (
531
- hasattr (mod , "pytest_plugins" )
532
- and self ._configured
533
- and not self ._using_pyargs
534
- ):
535
- _fail_on_non_top_pytest_plugins (conftestpath , self ._confcutdir )
536
517
except Exception as e :
537
518
raise ConftestImportFailure (conftestpath , sys .exc_info ()) from e
538
519
520
+ self ._check_non_top_pytest_plugins (mod , conftestpath )
521
+
539
522
self ._conftest_plugins .add (mod )
540
523
self ._conftestpath2mod [key ] = mod
541
524
dirpath = conftestpath .dirpath ()
@@ -548,6 +531,23 @@ def _importconftest(self, conftestpath):
548
531
self .consider_conftest (mod )
549
532
return mod
550
533
534
+ def _check_non_top_pytest_plugins (self , mod , conftestpath ):
535
+ if (
536
+ hasattr (mod , "pytest_plugins" )
537
+ and self ._configured
538
+ and not self ._using_pyargs
539
+ ):
540
+ msg = (
541
+ "Defining 'pytest_plugins' in a non-top-level conftest is no longer supported:\n "
542
+ "It affects the entire test suite instead of just below the conftest as expected.\n "
543
+ " {}\n "
544
+ "Please move it to a top level conftest file at the rootdir:\n "
545
+ " {}\n "
546
+ "For more information, visit:\n "
547
+ " https://docs.pytest.org/en/latest/deprecations.html#pytest-plugins-in-non-top-level-conftest-files"
548
+ )
549
+ fail (msg .format (conftestpath , self ._confcutdir ), pytrace = False )
550
+
551
551
#
552
552
# API for bootstrapping plugin loading
553
553
#
0 commit comments