Skip to content

Commit 227fe87

Browse files
committed
factory: improve handling of fixture setup failures
- skip tests on windows (see actions/runner-images#1143) - skip tests on MacOS (actions/runner-images#2150)
1 parent d2dec0f commit 227fe87

File tree

2 files changed

+36
-19
lines changed

2 files changed

+36
-19
lines changed

Diff for: src/pytest_servers/exceptions.py

-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,3 @@ def __init__(self, msg: str, *args):
99

1010
class RemoteUnavailable(PytestServersException):
1111
"""Raise when the given remote is not available"""
12-
13-
def __init__(self, remote: str, *args):
14-
super().__init__(f"{remote} remote is not available", *args)

Diff for: src/pytest_servers/factory.py

+36-16
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1+
import os
2+
import sys
13
import tempfile
2-
from typing import TYPE_CHECKING, Optional
4+
from typing import Optional
35

4-
from pytest import TempPathFactory
6+
import pytest
57
from upath import UPath
68

79
from pytest_servers.exceptions import RemoteUnavailable
810
from pytest_servers.local import LocalPath
911
from pytest_servers.utils import random_string
1012

11-
if TYPE_CHECKING:
12-
from pytest import FixtureRequest
13-
1413

1514
class TempUPathFactory:
1615
"""Factory for temporary directories with universal-pathlib and mocked servers""" # noqa: E501
1716

1817
mock_remotes = {
19-
"azure": ("azurite", "_azure_connection_string"),
20-
"gcs": ("fake_gcs_server", "_gcs_endpoint_url"),
21-
"s3": ("s3_server", "_s3_endpoint_url"),
18+
# remote: (fixture_name, config attribute name, requires docker)
19+
"azure": ("azurite", "_azure_connection_string", True),
20+
"gcs": ("fake_gcs_server", "_gcs_endpoint_url", True),
21+
"s3": ("s3_server", "_s3_endpoint_url", False),
2222
}
2323

2424
def __init__(
@@ -27,38 +27,58 @@ def __init__(
2727
azure_connection_string: Optional[str] = None,
2828
gcs_endpoint_url: Optional[str] = None,
2929
):
30-
self._request: Optional["FixtureRequest"] = None
30+
self._request: Optional["pytest.FixtureRequest"] = None
3131

32-
self._local_path_factory: Optional["TempPathFactory"] = None
32+
self._local_path_factory: Optional["pytest.TempPathFactory"] = None
3333
self._azure_connection_string = azure_connection_string
3434
self._gcs_endpoint_url = gcs_endpoint_url
3535
self._s3_endpoint_url = s3_endpoint_url
3636

3737
@classmethod
3838
def from_request(
39-
cls, request: "FixtureRequest", *args, **kwargs
39+
cls, request: "pytest.FixtureRequest", *args, **kwargs
4040
) -> "TempUPathFactory":
4141
"""Create a factory according to pytest configuration."""
4242
tmp_upath_factory = cls(*args, **kwargs)
43-
tmp_upath_factory._local_path_factory = TempPathFactory.from_config(
44-
request.config, _ispytest=True
43+
tmp_upath_factory._local_path_factory = (
44+
pytest.TempPathFactory.from_config(request.config, _ispytest=True)
4545
)
4646
tmp_upath_factory._request = request
4747

4848
return tmp_upath_factory
4949

5050
def _mock_remote_setup(self, fs: "str") -> None:
5151
try:
52-
mock_remote_fixture, remote_config_name = self.mock_remotes[fs]
52+
(
53+
mock_remote_fixture,
54+
remote_config_name,
55+
needs_docker,
56+
) = self.mock_remotes[fs]
5357
except KeyError:
5458
raise RemoteUnavailable(f"No mock remote available for fs: {fs}")
5559

5660
if getattr(self, remote_config_name): # remote is already configured
5761
return
5862

63+
if needs_docker and os.environ.get("CI"):
64+
if sys.platform == "win32":
65+
pytest.skip(
66+
"disabled for Windows on Github Actions: "
67+
"https://github.com/actions/runner-images/issues/1143"
68+
)
69+
elif sys.platform == "darwin":
70+
pytest.skip(
71+
"disabled for MacOS on Github Actions: "
72+
"https://github.com/actions/runner-images/issues/2150"
73+
)
74+
5975
assert self._request
60-
remote_config = self._request.getfixturevalue(mock_remote_fixture)
61-
assert remote_config, f"Failed to setup remote for {fs}"
76+
try:
77+
remote_config = self._request.getfixturevalue(mock_remote_fixture)
78+
except pytest.FixtureLookupError:
79+
raise RemoteUnavailable(
80+
f'{fs}: Failed to setup "{mock_remote_fixture}" fixture'
81+
)
6282
setattr(self, remote_config_name, remote_config)
6383

6484
def mktemp(

0 commit comments

Comments
 (0)