Skip to content

Commit b0fadb6

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 3a4a494 commit b0fadb6

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
@@ -114,35 +113,18 @@ def get_user() -> Optional[str]:
114113
return None
115114

116115

117-
def pytest_configure(config) -> None:
118-
"""Create a TempdirFactory and attach it to the config object.
119-
120-
This is to comply with existing plugins which expect the handler to be
121-
available at pytest_configure time, but ideally should be moved entirely
122-
to the tmpdir_factory session fixture.
123-
"""
124-
mp = MonkeyPatch()
125-
tmppath_handler = TempPathFactory.from_config(config)
126-
t = TempdirFactory(tmppath_handler)
127-
config._cleanup.append(mp.undo)
128-
mp.setattr(config, "_tmp_path_factory", tmppath_handler, raising=False)
129-
mp.setattr(config, "_tmpdirhandler", t, raising=False)
130-
131-
132116
@pytest.fixture(scope="session")
133-
def tmpdir_factory(request: FixtureRequest) -> TempdirFactory:
117+
def tmpdir_factory(tmp_path_factory) -> TempdirFactory:
134118
"""Return a :class:`_pytest.tmpdir.TempdirFactory` instance for the test session.
135119
"""
136-
# Set dynamically by pytest_configure() above.
137-
return request.config._tmpdirhandler # type: ignore
120+
return TempdirFactory(tmp_path_factory)
138121

139122

140123
@pytest.fixture(scope="session")
141124
def tmp_path_factory(request: FixtureRequest) -> TempPathFactory:
142125
"""Return a :class:`_pytest.tmpdir.TempPathFactory` instance for the test session.
143126
"""
144-
# Set dynamically by pytest_configure() above.
145-
return request.config._tmp_path_factory # type: ignore
127+
return TempPathFactory.from_config(request.config)
146128

147129

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

0 commit comments

Comments
 (0)