Skip to content

Commit b838dc7

Browse files
Carreauhoodmane
authored andcommitted
Use parametrize test instead of fixture.
This is useful to run only a subset of test with --ff or --lf when trying to debug/fix a situation and should make further parametrisation a bit more easy. query_package is used only in a few location so I woudl also be tempted to make it only accept lists instead os str|list[str] but that's another discussion. We could further parametrize on for _index_urls in ( pkg1_index_url, [pkg1_index_url], [pkg2_index_url, pkg1_index_url], But it woudl be a bit more complicated.
1 parent 5d4a869 commit b838dc7

1 file changed

Lines changed: 23 additions & 36 deletions

File tree

tests/test_package_index.py

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -115,29 +115,15 @@ def test_contain_placeholder():
115115
assert not package_index._contain_placeholder("https://pkg-index.com/")
116116

117117

118-
async def _test_query_package(pkg1, pkg1_index_url, pkg2, pkg2_index_url):
119-
project_info = await package_index.query_package(pkg1, index_urls=[pkg1_index_url])
120-
121-
assert project_info.name == pkg1
122-
assert project_info.releases
123-
124-
project_info = await package_index.query_package(pkg1, index_urls=pkg1_index_url)
125-
126-
assert project_info.name == pkg1
127-
assert project_info.releases
128-
129-
project_info = await package_index.query_package(
130-
pkg1, index_urls=[pkg2_index_url, pkg1_index_url]
131-
)
132-
133-
assert project_info.name == pkg1
134-
assert project_info.releases
135-
136-
with pytest.raises(ValueError, match="Can't fetch metadata"):
137-
await package_index.query_package(pkg1, index_urls=[pkg2_index_url])
138-
139-
140118
@pytest.mark.asyncio
119+
@pytest.mark.parametrize(
120+
"mock_fixture",
121+
(
122+
"mock_package_index_json_api",
123+
"mock_package_index_simple_json_api",
124+
"mock_package_index_simple_html_api",
125+
),
126+
)
141127
@pytest.mark.parametrize(
142128
"pkg1, pkg2",
143129
[
@@ -147,19 +133,20 @@ async def _test_query_package(pkg1, pkg1_index_url, pkg2, pkg2_index_url):
147133
("numpy", "black"),
148134
],
149135
)
150-
async def test_query_package(
151-
pkg1,
152-
pkg2,
153-
mock_package_index_json_api,
154-
mock_package_index_simple_json_api,
155-
mock_package_index_simple_html_api,
156-
):
157-
for gen_mock_server in (
158-
mock_package_index_json_api,
159-
mock_package_index_simple_json_api,
160-
mock_package_index_simple_html_api,
136+
async def test_query_package(mock_fixture, pkg1, pkg2, request):
137+
gen_mock_server = request.getfixturevalue(mock_fixture)
138+
pkg1_index_url = gen_mock_server(pkgs=[pkg1])
139+
pkg2_index_url = gen_mock_server(pkgs=[pkg2])
140+
141+
for _index_urls in (
142+
pkg1_index_url,
143+
[pkg1_index_url],
144+
[pkg2_index_url, pkg1_index_url],
161145
):
162-
mock_server_1 = gen_mock_server(pkgs=[pkg1])
163-
mock_server_2 = gen_mock_server(pkgs=[pkg2])
146+
project_info = await package_index.query_package(pkg1, index_urls=_index_urls)
147+
148+
assert project_info.name == pkg1
149+
assert project_info.releases
164150

165-
await _test_query_package(pkg1, mock_server_1, pkg2, mock_server_2)
151+
with pytest.raises(ValueError, match="Can't fetch metadata"):
152+
await package_index.query_package(pkg1, index_urls=[pkg2_index_url])

0 commit comments

Comments
 (0)