tmpdir: clean up indirection via config for factories (#6767)

Remove `_tmp_path_factory` and `_tmpdirhandler` from the config object.

- `_tmpdirhandler` has been deprecated since 2.8.0 (0f52856f9), 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 (16e2737da).
This commit is contained in:
Daniel Hahler 2020-02-20 12:48:33 +01:00 committed by GitHub
parent 82f5986424
commit 8a1633c3b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 21 deletions

View File

@ -14,7 +14,6 @@ from .pathlib import make_numbered_dir
from .pathlib import make_numbered_dir_with_cleanup from .pathlib import make_numbered_dir_with_cleanup
from .pathlib import Path from .pathlib import Path
from _pytest.fixtures import FixtureRequest from _pytest.fixtures import FixtureRequest
from _pytest.monkeypatch import MonkeyPatch
@attr.s @attr.s
@ -135,35 +134,18 @@ def get_user() -> Optional[str]:
return None return None
def pytest_configure(config) -> None:
"""Create a TempdirFactory and attach it to the config object.
This is to comply with existing plugins which expect the handler to be
available at pytest_configure time, but ideally should be moved entirely
to the tmpdir_factory session fixture.
"""
mp = MonkeyPatch()
tmppath_handler = TempPathFactory.from_config(config)
t = TempdirFactory(tmppath_handler)
config._cleanup.append(mp.undo)
mp.setattr(config, "_tmp_path_factory", tmppath_handler, raising=False)
mp.setattr(config, "_tmpdirhandler", t, raising=False)
@pytest.fixture(scope="session") @pytest.fixture(scope="session")
def tmpdir_factory(request: FixtureRequest) -> TempdirFactory: def tmpdir_factory(tmp_path_factory) -> TempdirFactory:
"""Return a :class:`_pytest.tmpdir.TempdirFactory` instance for the test session. """Return a :class:`_pytest.tmpdir.TempdirFactory` instance for the test session.
""" """
# Set dynamically by pytest_configure() above. return TempdirFactory(tmp_path_factory)
return request.config._tmpdirhandler # type: ignore
@pytest.fixture(scope="session") @pytest.fixture(scope="session")
def tmp_path_factory(request: FixtureRequest) -> TempPathFactory: def tmp_path_factory(request: FixtureRequest) -> TempPathFactory:
"""Return a :class:`_pytest.tmpdir.TempPathFactory` instance for the test session. """Return a :class:`_pytest.tmpdir.TempPathFactory` instance for the test session.
""" """
# Set dynamically by pytest_configure() above. return TempPathFactory.from_config(request.config)
return request.config._tmp_path_factory # type: ignore
def _mk_tmp(request: FixtureRequest, factory: TempPathFactory) -> Path: def _mk_tmp(request: FixtureRequest, factory: TempPathFactory) -> Path: