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

Revert "tmpdir: clean up indirection via config for factories" #6992

Merged
merged 1 commit into from Apr 10, 2020
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions changelog/6992.bugfix.rst
@@ -0,0 +1 @@
Revert "tmpdir: clean up indirection via config for factories" #6767 as it breaks pytest-xdist.
24 changes: 21 additions & 3 deletions src/_pytest/tmpdir.py
Expand Up @@ -14,6 +14,7 @@
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 @@ -134,18 +135,35 @@ 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but ideally should be moved entirely to the tmpdir_factory session fixture.

Maybe remove this?
It cannot be moved really if plugins want to use it before fixtures are being used.

As a followup it should go into the config's store probably, and then even get documented/exposed properly.

We can merge/revert as is - but certainly the "ideally" made me think less about removing/following that advice.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tmpdir factory is actually the prime example for a fixture which has a component that runs on the coordinator in case of shared systems

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it does not work / can be used when it is required before the test run already though, e.g. when used with/for startup args.
However, with xdist it could also not use --basetemp then, but the coordinator's component - I assume that's what you've meant?

In general though basetemp appears to be a useful property to provide via config by default, which would then either be retrieved via the tmpdir plugin, or generated via its class. The tmpdir plugin could also instead just use the universal property from the config then - the --basetemp option is in main already, so it could handle the default there then.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider adjusting the doc so that it is clear that it is used by e.g. xdist.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also please squash then (assuming you are not squash-merging).

"""
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(tmp_path_factory) -> TempdirFactory:
def tmpdir_factory(request: FixtureRequest) -> TempdirFactory:
"""Return a :class:`_pytest.tmpdir.TempdirFactory` instance for the test session.
"""
return TempdirFactory(tmp_path_factory)
# Set dynamically by pytest_configure() above.
return request.config._tmpdirhandler # type: ignore


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


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