@@ -400,27 +400,11 @@ def Node_fspath_set(self: Node, value: LEGACY_PATH) -> None:
400400 self .path = Path (value )
401401
402402
403- @pytest .hookimpl
404- def pytest_configure (config : pytest .Config ) -> None :
403+ @pytest .hookimpl (tryfirst = True )
404+ def pytest_load_initial_conftests (early_config : pytest .Config ) -> None :
405+ """Monkeypatch legacy path attributes in several classes, as early as possible."""
405406 mp = pytest .MonkeyPatch ()
406- config .add_cleanup (mp .undo )
407-
408- if config .pluginmanager .has_plugin ("tmpdir" ):
409- # Create TmpdirFactory and attach it to the config object.
410- #
411- # This is to comply with existing plugins which expect the handler to be
412- # available at pytest_configure time, but ideally should be moved entirely
413- # to the tmpdir_factory session fixture.
414- try :
415- tmp_path_factory = config ._tmp_path_factory # type: ignore[attr-defined]
416- except AttributeError :
417- # tmpdir plugin is blocked.
418- pass
419- else :
420- _tmpdirhandler = TempdirFactory (tmp_path_factory , _ispytest = True )
421- mp .setattr (config , "_tmpdirhandler" , _tmpdirhandler , raising = False )
422-
423- config .pluginmanager .register (LegacyTmpdirPlugin , "legacypath-tmpdir" )
407+ early_config .add_cleanup (mp .undo )
424408
425409 # Add Cache.makedir().
426410 mp .setattr (pytest .Cache , "makedir" , Cache_makedir , raising = False )
@@ -452,6 +436,29 @@ def pytest_configure(config: pytest.Config) -> None:
452436 mp .setattr (Node , "fspath" , property (Node_fspath , Node_fspath_set ), raising = False )
453437
454438
439+ @pytest .hookimpl
440+ def pytest_configure (config : pytest .Config ) -> None :
441+ """Installs the LegacyTmpdirPlugin if the ``tmpdir`` plugin is also installed."""
442+ if config .pluginmanager .has_plugin ("tmpdir" ):
443+ mp = pytest .MonkeyPatch ()
444+ config .add_cleanup (mp .undo )
445+ # Create TmpdirFactory and attach it to the config object.
446+ #
447+ # This is to comply with existing plugins which expect the handler to be
448+ # available at pytest_configure time, but ideally should be moved entirely
449+ # to the tmpdir_factory session fixture.
450+ try :
451+ tmp_path_factory = config ._tmp_path_factory # type: ignore[attr-defined]
452+ except AttributeError :
453+ # tmpdir plugin is blocked.
454+ pass
455+ else :
456+ _tmpdirhandler = TempdirFactory (tmp_path_factory , _ispytest = True )
457+ mp .setattr (config , "_tmpdirhandler" , _tmpdirhandler , raising = False )
458+
459+ config .pluginmanager .register (LegacyTmpdirPlugin , "legacypath-tmpdir" )
460+
461+
455462@pytest .hookimpl
456463def pytest_plugin_registered (
457464 plugin : object , manager : pytest .PytestPluginManager
0 commit comments