Skip to content

Commit ef669ff

Browse files
committed
Fix tmp_path_factory usage
1 parent b429202 commit ef669ff

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/pytest_servers/factory.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,18 @@ def __init__(
5353
def from_request(
5454
cls: type[TempUPathFactory],
5555
request: pytest.FixtureRequest,
56+
tmp_path_factory: pytest.TempPathFactory | None = None,
5657
*args,
5758
**kwargs,
5859
) -> TempUPathFactory:
5960
"""Create a factory according to pytest configuration."""
60-
tmp_upath_factory = cls(*args, **kwargs)
61-
tmp_upath_factory._local_path_factory = ( # noqa: SLF001
62-
pytest.TempPathFactory.from_config(
61+
if tmp_path_factory is None:
62+
tmp_path_factory = pytest.TempPathFactory.from_config(
6363
request.config,
6464
_ispytest=True,
6565
)
66-
)
66+
tmp_upath_factory = cls(*args, **kwargs)
67+
tmp_upath_factory._local_path_factory = tmp_path_factory # noqa: SLF001
6768
tmp_upath_factory._request = request # noqa: SLF001
6869

6970
return tmp_upath_factory

src/pytest_servers/fixtures.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ def versioning(): # noqa: ANN201
2323

2424

2525
@pytest.fixture(scope="session")
26-
def tmp_upath_factory(request: pytest.FixtureRequest) -> TempUPathFactory:
26+
def tmp_upath_factory(
27+
request: pytest.FixtureRequest,
28+
tmp_path_factory: pytest.TempPathFactory,
29+
) -> TempUPathFactory:
2730
"""Return a TempUPathFactory instance for the test session."""
28-
return TempUPathFactory.from_request(request)
31+
return TempUPathFactory.from_request(request, tmp_path_factory)
2932

3033

3134
@pytest.fixture

0 commit comments

Comments
 (0)