Easy way to print hardware info at the beginning of a session. #10744
-
Is there an easy way to print information about the machine's hardware (CPU/RAM/...) at the beginning of a pytest session? Background: I'm working on a numerics library (linalg package for a rendering engine) and I'm trying to get to the bottom of a sporadic failure where a seemingly simple function (norm of a vector) sometimes produces slightly inaccurate results (near machine precision, ie., |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi, You can implement the pytest_report_header hook in your topmost conftest.py file to add any information to the header. |
Beta Was this translation helpful? Give feedback.
-
For future reference, this is the hook I ended up with: def pytest_report_header(config, start_path, startdir):
# report the CPU model to allow detecting platform-specific problems
if platform.system() == "Windows":
name = (
subprocess.check_output(["wmic", "cpu", "get", "name"])
.decode()
.strip()
.split("\n")[1]
)
cpu_info = " ".join([name])
elif platform.system() == "Linux":
info_string = subprocess.check_output(["lscpu"]).decode()
for line in info_string.split("\n"):
if line.startswith("Model name"):
cpu_info = line[33:]
break
else:
cpu_info = platform.processor()
return "CPU: " + cpu_info This will add something like the following at the beginning of the logs:
|
Beta Was this translation helpful? Give feedback.
Hi,
You can implement the pytest_report_header hook in your topmost conftest.py file to add any information to the header.