Skip to content

Commit e976a7b

Browse files
Reduce duplication between test_latest_version tests using parametrize
Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/82e0a287-6c51-4f8f-a52a-21c95007abec Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
1 parent 0ac5b73 commit e976a7b

1 file changed

Lines changed: 26 additions & 104 deletions

File tree

tests/usethis/test_fallback.py

Lines changed: 26 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -26,115 +26,37 @@ def _skip_on_github_error(err: GitHubTagError) -> None:
2626
pytest.skip("Failed to fetch GitHub tags (connection issues); skipping test")
2727

2828

29-
class TestFallbackUVVersion:
29+
class TestLatestVersion:
3030
@pytest.mark.usefixtures("_vary_network_conn")
31-
def test_latest_version(self):
32-
if os.getenv("CI"):
33-
pytest.skip("Avoid flaky pipelines by testing version bumps manually")
34-
35-
try:
36-
assert (
37-
get_github_latest_tag(owner="astral-sh", repo="uv")
38-
== FALLBACK_UV_VERSION
39-
)
40-
except GitHubTagError as err:
41-
_skip_on_github_error(err)
42-
raise err
43-
44-
45-
class TestFallbackHatchlingVersion:
46-
@pytest.mark.usefixtures("_vary_network_conn")
47-
def test_latest_version(self):
48-
if os.getenv("CI"):
49-
pytest.skip("Avoid flaky pipelines by testing version bumps manually")
50-
51-
try:
52-
assert (
53-
get_github_latest_tag(owner="pypa", repo="hatch")
54-
== f"hatchling-v{FALLBACK_HATCHLING_VERSION}"
55-
)
56-
except GitHubTagError as err:
57-
_skip_on_github_error(err)
58-
raise err
59-
60-
61-
class TestPreCommitVersion:
62-
@pytest.mark.usefixtures("_vary_network_conn")
63-
def test_latest_version(self):
64-
if os.getenv("CI"):
65-
pytest.skip("Avoid flaky pipelines by testing version bumps manually")
66-
67-
try:
68-
assert (
69-
get_github_latest_tag(owner="pre-commit", repo="pre-commit")
70-
== f"v{FALLBACK_PRE_COMMIT_VERSION}"
71-
)
72-
except GitHubTagError as err:
73-
_skip_on_github_error(err)
74-
raise err
75-
76-
77-
class TestRuffVersion:
78-
@pytest.mark.usefixtures("_vary_network_conn")
79-
def test_latest_version(self):
80-
if os.getenv("CI"):
81-
pytest.skip("Avoid flaky pipelines by testing version bumps manually")
82-
83-
try:
84-
assert (
85-
get_github_latest_tag(owner="astral-sh", repo="ruff-pre-commit")
86-
== FALLBACK_RUFF_VERSION
87-
)
88-
except GitHubTagError as err:
89-
_skip_on_github_error(err)
90-
raise err
91-
92-
93-
class TestSyncWithUVVersion:
94-
@pytest.mark.usefixtures("_vary_network_conn")
95-
def test_latest_version(self):
96-
if os.getenv("CI"):
97-
pytest.skip("Avoid flaky pipelines by testing version bumps manually")
98-
99-
try:
100-
assert (
101-
get_github_latest_tag(owner="tsvikas", repo="sync-with-uv")
102-
== FALLBACK_SYNC_WITH_UV_VERSION
103-
)
104-
except GitHubTagError as err:
105-
_skip_on_github_error(err)
106-
raise err
107-
108-
109-
class TestCodespellVersion:
110-
@pytest.mark.usefixtures("_vary_network_conn")
111-
def test_latest_version(self):
112-
if os.getenv("CI"):
113-
pytest.skip("Avoid flaky pipelines by testing version bumps manually")
114-
115-
try:
116-
assert (
117-
get_github_latest_tag(owner="codespell-project", repo="codespell")
118-
== FALLBACK_CODESPELL_VERSION
119-
)
120-
except GitHubTagError as err:
121-
_skip_on_github_error(err)
122-
raise err
123-
124-
125-
class TestPyprojectFmtVersion:
126-
@pytest.mark.usefixtures("_vary_network_conn")
127-
def test_latest_version(self):
31+
@pytest.mark.parametrize(
32+
("owner", "repo", "expected_tag"),
33+
[
34+
("astral-sh", "uv", FALLBACK_UV_VERSION),
35+
("pypa", "hatch", f"hatchling-v{FALLBACK_HATCHLING_VERSION}"),
36+
("pre-commit", "pre-commit", f"v{FALLBACK_PRE_COMMIT_VERSION}"),
37+
("astral-sh", "ruff-pre-commit", FALLBACK_RUFF_VERSION),
38+
("tsvikas", "sync-with-uv", FALLBACK_SYNC_WITH_UV_VERSION),
39+
("codespell-project", "codespell", FALLBACK_CODESPELL_VERSION),
40+
# N.B. this is the pre-commit mirror, it can lag behind the main repo
41+
# at https://github.com/tox-dev/toml-fmt/tree/main/pyproject-fmt
42+
("tox-dev", "pyproject-fmt", FALLBACK_PYPROJECT_FMT_VERSION),
43+
],
44+
ids=[
45+
"uv",
46+
"hatchling",
47+
"pre-commit",
48+
"ruff",
49+
"sync-with-uv",
50+
"codespell",
51+
"pyproject-fmt",
52+
],
53+
)
54+
def test_latest_version(self, owner: str, repo: str, expected_tag: str):
12855
if os.getenv("CI"):
12956
pytest.skip("Avoid flaky pipelines by testing version bumps manually")
13057

13158
try:
132-
# N.B. this is the pre-commit mirror, it can lag behind the main repo
133-
# at https://github.com/tox-dev/toml-fmt/tree/main/pyproject-fmt
134-
assert (
135-
get_github_latest_tag(owner="tox-dev", repo="pyproject-fmt")
136-
== FALLBACK_PYPROJECT_FMT_VERSION
137-
)
59+
assert get_github_latest_tag(owner=owner, repo=repo) == expected_tag
13860
except GitHubTagError as err:
13961
_skip_on_github_error(err)
14062
raise err

0 commit comments

Comments
 (0)