Skip to content

Commit d6e6b96

Browse files
authored
Merge pull request #9286 from bluetech/legacypath-subplugins
legacypath: support late-loading of pytester plugin
2 parents f87df9c + 63899c7 commit d6e6b96

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/_pytest/legacypath.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,13 +400,11 @@ def Node_fspath_set(self: Node, value: LEGACY_PATH) -> None:
400400
self.path = Path(value)
401401

402402

403+
@pytest.hookimpl
403404
def pytest_configure(config: pytest.Config) -> None:
404405
mp = pytest.MonkeyPatch()
405406
config.add_cleanup(mp.undo)
406407

407-
if config.pluginmanager.has_plugin("pytester"):
408-
config.pluginmanager.register(LegacyTestdirPlugin, "legacypath-pytester")
409-
410408
if config.pluginmanager.has_plugin("tmpdir"):
411409
# Create TmpdirFactory and attach it to the config object.
412410
#
@@ -452,3 +450,14 @@ def pytest_configure(config: pytest.Config) -> None:
452450

453451
# Add Node.fspath property.
454452
mp.setattr(Node, "fspath", property(Node_fspath, Node_fspath_set), raising=False)
453+
454+
455+
@pytest.hookimpl
456+
def pytest_plugin_registered(
457+
plugin: object, manager: pytest.PytestPluginManager
458+
) -> None:
459+
# pytester is not loaded by default and is commonly loaded from a conftest,
460+
# so checking for it in `pytest_configure` is not enough.
461+
is_pytester = plugin is manager.get_plugin("pytester")
462+
if is_pytester and not manager.is_registered(LegacyTestdirPlugin):
463+
manager.register(LegacyTestdirPlugin, "legacypath-pytester")

0 commit comments

Comments
 (0)