Skip to content

Commit 4f1fbb6

Browse files
committed
Enhance pytest report header to include Git branch, commit, and message details
1 parent 88a5efd commit 4f1fbb6

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

cdl/tests/conftest.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ def pytest_report_header(config): # pylint: disable=unused-argument
5353
qtbindings_version = qtpy.PYQT_VERSION
5454
infolist = [
5555
f"DataLab {cdl.__version__} [Plugins: {nfstr if nfstr else 'None'}]",
56-
f"guidata {guidata.__version__}, PlotPy {plotpy.__version__}",
57-
f"PythonQwt {qwt.__version__}, "
56+
f" guidata {guidata.__version__}, PlotPy {plotpy.__version__}",
57+
f" PythonQwt {qwt.__version__}, "
5858
f"{qtpy.API_NAME} {qtbindings_version} [Qt version: {qtpy.QT_VERSION}]",
59-
f"NumPy {numpy.__version__}, SciPy {scipy.__version__}, "
59+
f" NumPy {numpy.__version__}, SciPy {scipy.__version__}, "
6060
f"h5py {h5py.__version__}, scikit-image {skimage.__version__}",
6161
]
6262
try:
@@ -65,17 +65,32 @@ def pytest_report_header(config): # pylint: disable=unused-argument
6565
infolist[-1] += f", OpenCV {cv2.__version__}"
6666
except ImportError:
6767
pass
68+
envlist = []
6869
for vname in ("CDL_DATA", "PYTHONPATH", "DEBUG", "QT_API", "QT_QPA_PLATFORM"):
6970
value = os.environ.get(vname, "")
7071
if value:
71-
infolist.append(f"{vname}: {value}")
72+
if vname == "PYTHONPATH":
73+
pathlist = value.split(os.pathsep)
74+
envlist.append(f" {vname}:")
75+
envlist.extend(f" {p}" for p in pathlist if p)
76+
else:
77+
envlist.append(f" {vname}: {value}")
78+
if envlist:
79+
infolist.append("Environment variables:")
80+
infolist.extend(envlist)
7281
sco = subprocess.check_output
7382
try:
83+
gitlist = ["Git information:"]
7484
branch = sco(["git", "rev-parse", "--abbrev-ref", "HEAD"], text=True).strip()
7585
commit = sco(["git", "rev-parse", "--short", "HEAD"], text=True).strip()
7686
message = sco(["git", "log", "-1", "--pretty=%B"], text=True).strip()
77-
message = message[:35] + "[…]" if len(message) > 35 else message
78-
infolist.append(f"Git branch: {branch}, commit: {message} ({commit})")
87+
if len(message.splitlines()) > 1:
88+
message = message.splitlines()[0]
89+
message = message[:60] + "[…]" if len(message) > 60 else message
90+
gitlist.append(f" Branch: {branch}")
91+
gitlist.append(f" Commit: {commit}")
92+
gitlist.append(f" Message: {message}")
93+
infolist.extend(gitlist)
7994
except (subprocess.CalledProcessError, FileNotFoundError):
8095
pass
8196
return infolist

0 commit comments

Comments
 (0)