Skip to content

Commit 6c37baa

Browse files
committed
tmpdir: clean up indirection via config for factories
Remove `_tmp_path_factory` and `_tmpdirhandler` from the config object. - `_tmpdirhandler` has been deprecated since 2.8.0 (0f52856), when `tmpdir_factory` has been added. - `_tmp_path_factory` should have probably never been added there in the first place, but maybe just used the same pattern (16e2737).
1 parent 7c09d88 commit 6c37baa

File tree

1 file changed

+3
-21
lines changed

1 file changed

+3
-21
lines changed

src/_pytest/tmpdir.py

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from .pathlib import make_numbered_dir_with_cleanup
1515
from .pathlib import Path
1616
from _pytest.fixtures import FixtureRequest
17-
from _pytest.monkeypatch import MonkeyPatch
1817

1918

2019
@attr.s
@@ -135,35 +134,18 @@ def get_user() -> Optional[str]:
135134
return None
136135

137136

138-
def pytest_configure(config) -> None:
139-
"""Create a TempdirFactory and attach it to the config object.
140-
141-
This is to comply with existing plugins which expect the handler to be
142-
available at pytest_configure time, but ideally should be moved entirely
143-
to the tmpdir_factory session fixture.
144-
"""
145-
mp = MonkeyPatch()
146-
tmppath_handler = TempPathFactory.from_config(config)
147-
t = TempdirFactory(tmppath_handler)
148-
config._cleanup.append(mp.undo)
149-
mp.setattr(config, "_tmp_path_factory", tmppath_handler, raising=False)
150-
mp.setattr(config, "_tmpdirhandler", t, raising=False)
151-
152-
153137
@pytest.fixture(scope="session")
154-
def tmpdir_factory(request: FixtureRequest) -> TempdirFactory:
138+
def tmpdir_factory(tmp_path_factory) -> TempdirFactory:
155139
"""Return a :class:`_pytest.tmpdir.TempdirFactory` instance for the test session.
156140
"""
157-
# Set dynamically by pytest_configure() above.
158-
return request.config._tmpdirhandler # type: ignore
141+
return TempdirFactory(tmp_path_factory)
159142

160143

161144
@pytest.fixture(scope="session")
162145
def tmp_path_factory(request: FixtureRequest) -> TempPathFactory:
163146
"""Return a :class:`_pytest.tmpdir.TempPathFactory` instance for the test session.
164147
"""
165-
# Set dynamically by pytest_configure() above.
166-
return request.config._tmp_path_factory # type: ignore
148+
return TempPathFactory.from_config(request.config)
167149

168150

169151
def _mk_tmp(request: FixtureRequest, factory: TempPathFactory) -> Path:

0 commit comments

Comments
 (0)