Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tmpdir: clean up indirection via config for factories #6767

Merged
merged 1 commit into from Feb 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 3 additions & 21 deletions src/_pytest/tmpdir.py
Expand Up @@ -14,7 +14,6 @@
from .pathlib import make_numbered_dir_with_cleanup
from .pathlib import Path
from _pytest.fixtures import FixtureRequest
from _pytest.monkeypatch import MonkeyPatch


@attr.s
Expand Down Expand Up @@ -135,35 +134,18 @@ def get_user() -> Optional[str]:
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")
def tmpdir_factory(request: FixtureRequest) -> TempdirFactory:
def tmpdir_factory(tmp_path_factory) -> TempdirFactory:
"""Return a :class:`_pytest.tmpdir.TempdirFactory` instance for the test session.
"""
# Set dynamically by pytest_configure() above.
return request.config._tmpdirhandler # type: ignore
return TempdirFactory(tmp_path_factory)


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


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