Skip to content

Commit

Permalink
test: Add an _xfail_due_to_version helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Sep 18, 2023
1 parent b98ef02 commit 437c192
Showing 1 changed file with 32 additions and 20 deletions.
52 changes: 32 additions & 20 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@
NEW_SURVEY_NAME = "New Survey"


def _xfail_due_to_version(
request: pytest.FixtureRequest,
server_version: semver.Version,
check_version: tuple[int, ...],
reason: str,
**kwargs: t.Any,
) -> None:
if server_version < check_version:
request.node.add_marker(
pytest.mark.xfail(
reason=reason,
raises=requests.exceptions.HTTPError,
**kwargs,
),
)


@pytest.fixture(scope="module")
def client(
integration_url: str,
Expand Down Expand Up @@ -257,16 +274,12 @@ def test_quota(
survey_id: int,
):
"""Test quota methods."""
if server_version < (6, 0, 0):
request.node.add_marker(
pytest.mark.xfail(
reason=(
"Quota RPC methods are not supported in LimeSurvey "
f"{server_version} < 6.0.0"
),
raises=requests.exceptions.HTTPError,
),
)
_xfail_due_to_version(
request,
server_version,
(6, 0, 0),
f"Quota RPC methods are not supported in LimeSurvey {server_version} < 6.0.0",
)

with pytest.raises(LimeSurveyStatusError, match="No quotas found"):
client.list_quotas(survey_id)
Expand Down Expand Up @@ -566,16 +579,15 @@ def test_get_available_site_settings(
server_version: semver.Version,
):
"""Test getting available site settings."""
if server_version < (6, 0, 0):
request.node.add_marker(
pytest.mark.xfail(
reason=(
"RPC method `get_available_site_settings` is not supported in "
f"LimeSurvey {server_version} < 6.0.0"
),
raises=requests.exceptions.HTTPError,
),
)
_xfail_due_to_version(
request,
server_version,
(6, 0, 0),
(
"RPC method `get_available_site_settings` is not supported in LimeSurvey "
f"{server_version} < 6.0.0"
),
)
assert client.get_available_site_settings()


Expand Down

0 comments on commit 437c192

Please sign in to comment.