Skip to content

Commit b611396

Browse files
committed
turn get_package_dependencies() into fixture
1 parent ec378cd commit b611396

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

tests/conftest.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import configparser
2+
from pathlib import Path
3+
from typing import List
4+
5+
import pytest
6+
from packaging.requirements import Requirement
7+
8+
SETUP_CFG_FILE = Path(__file__).parent.parent / "setup.cfg"
9+
10+
11+
@pytest.fixture(scope="session")
12+
def cfg_requirements() -> List[Requirement]:
13+
"""A fixture for getting the requirements of from setup.cfg."""
14+
parser = configparser.ConfigParser()
15+
parser.read(SETUP_CFG_FILE)
16+
17+
return [
18+
Requirement(line)
19+
for line in parser.get("options", "install_requires").splitlines()
20+
if line
21+
]

tests/test_dependencies.py

+4-22
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,16 @@
11
"""Tests to ensure that the dependency declarations are sane.
22
"""
33

4-
import configparser
54
import pprint
6-
from functools import lru_cache
7-
from pathlib import Path
8-
from typing import List
95

106
import pytest
117
from packaging.requirements import Requirement
128

13-
SETUP_CFG_FILE = Path(__file__).parent.parent / "setup.cfg"
14-
159

1610
def is_pinned(requirement: Requirement) -> bool:
1711
return "==" in str(requirement.specifier)
1812

1913

20-
@lru_cache(maxsize=None)
21-
def get_package_dependencies() -> List[Requirement]:
22-
"""A cached reader for getting dependencies of this package."""
23-
parser = configparser.ConfigParser()
24-
parser.read(SETUP_CFG_FILE)
25-
26-
return [
27-
Requirement(line)
28-
for line in parser.get("options", "install_requires").splitlines()
29-
if line
30-
]
31-
32-
3314
# The ordering of these markers is important, and is used in test names.
3415
# The tests, when run, look like: PyPy-3.6-Linux-aarch64` (bottom-first)
3516
@pytest.mark.parametrize("platform_machine", ["x86", "x86_64", "aarch64", "ppc64le", "s390x", "arm64", "loongarch64"])
@@ -41,6 +22,7 @@ def test_has_at_most_one_pinned_dependency(
4122
platform_system,
4223
python_version,
4324
platform_python_implementation,
25+
cfg_requirements,
4426
):
4527
# These are known to be platforms that are not valid / possible at this time.
4628
# due the the sheer variety, the default assumption is that a given combination
@@ -84,7 +66,7 @@ def test_has_at_most_one_pinned_dependency(
8466
}
8567

8668
filtered_requirements = []
87-
for req in get_package_dependencies():
69+
for req in cfg_requirements:
8870
assert req.marker
8971
if not req.marker.evaluate(environment):
9072
continue
@@ -131,9 +113,9 @@ def test_has_at_most_one_pinned_dependency(
131113
), f"{log_msg}.\n{pprint.pformat(environment)}"
132114

133115

134-
def test_valid_numpy_is_installed():
116+
def test_valid_numpy_is_installed(cfg_requirements):
135117
filtered_requirements = []
136-
for req in get_package_dependencies():
118+
for req in cfg_requirements:
137119
if req.marker.evaluate():
138120
filtered_requirements.append(req)
139121

0 commit comments

Comments
 (0)