Skip to content

Commit 869ae51

Browse files
Enhance pytest report header to format package paths for better readability
- Updated the path representation in the pytest report header to replace 'site-packages' with 'site:.' and the current working directory with 'CWD:.' for improved clarity.
1 parent 2319a9d commit 869ae51

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

testing/conftest.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,15 @@ def pytest_report_header() -> list[str]:
3838
for pkg in VERSION_PKGS:
3939
pkg_version = version(pkg)
4040
path = __import__(pkg).__file__
41-
res.append(f"{pkg} version {pkg_version} from {path!r}")
41+
if path and "site-packages" in path:
42+
# Replace everything up to and including site-packages with site::
43+
parts = path.split("site-packages", 1)
44+
if len(parts) > 1:
45+
path = "site:." + parts[1]
46+
elif path and str(Path.cwd()) in path:
47+
# Replace current working directory with CWD::
48+
path = path.replace(str(Path.cwd()), "CWD:.")
49+
res.append(f"{pkg} version {pkg_version} from {path}")
4250
return res
4351

4452

0 commit comments

Comments
 (0)