Skip to content

Commit bd9f573

Browse files
committed
Auto-discover pytest paths
Look for pytest paths in the `pyproject.toml` file and add them to `extra_paths` automatically. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 9c077b9 commit bd9f573

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/frequenz/repo/config/nox/config.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ class Config:
8484
tools invoked by the sessions.
8585
"""
8686

87+
def __post_init__(self) -> None:
88+
"""Initialize the configuration object.
89+
90+
This will add extra paths discovered in config files and other sources.
91+
"""
92+
for path in util.discover_paths():
93+
if path not in self.extra_paths:
94+
self.extra_paths.append(path)
95+
8796
def copy(self, /) -> Self:
8897
"""Create a new object as a copy of self.
8998

src/frequenz/repo/config/nox/util.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,30 @@ def min_dependencies() -> list[str]:
170170
else:
171171
raise RuntimeError(f"Minimum requirement is not set: {dep}")
172172
return min_deps
173+
174+
175+
def discover_paths() -> list[str]:
176+
"""Discover paths to check.
177+
178+
Discover the paths to check by looking into different sources, like the
179+
`pyproject.toml` file.
180+
181+
Currently the following paths are discovered:
182+
183+
- The `testpaths` option in the `tools.pytest.ini_options` section of
184+
`pyproject.toml`.
185+
186+
Returns:
187+
The discovered paths to check.
188+
"""
189+
with open("pyproject.toml", "rb") as toml_file:
190+
data = tomllib.load(toml_file)
191+
192+
testpaths = (
193+
data.get("tool", {})
194+
.get("pytest", {})
195+
.get("ini_options", {})
196+
.get("testpaths", [])
197+
)
198+
199+
return testpaths

0 commit comments

Comments
 (0)