When running pytest -s --co, it lists the collected tests but doesn’t show the actual parameter values — only labels like pytest_parameters0.
The goal is to retrieve both the test names and their explicit parameters before execution. Some have tried using hooks such as pytest_collection_modify_items, but that doesn’t expose parameter data directly.
A better option is to implement the pytest_collection_finish hook, which gives access to the final list of collected tests, including their parameterized names and values, allowing you to log or export them as needed.
I’ve bumped into the same need before just wanted a clean list of every test with its parameters before execution. The simplest approach that worked for me was dropping a pytest_collection_finish hook into conftest.py.
def pytest_collection_finish(session):
for item in session.items:
print(item.nodeid)
Because it runs after collection is fully done, the nodeid already contains the expanded parameter values not those vague pytest_parameters0 placeholders you see with pytest -s --co. So instead of test_example[param1], you’ll actually get test_example[param=10-mode=fast]. Super handy when all you need is visibility without running the suite.
Adding to what @dipen-soni shared if you need a bit more structure than just printing IDs, you can still stick with pytest_collection_finish, but combine it with data extraction from item.callspec.params.
def pytest_collection_finish(session):
for item in session.items:
if hasattr(item, "callspec"):
print(item.name, item.callspec.params)
This way you don’t just see a long test string you get an actual dictionary of parameters.
I once used this to export every test + param set into a CSV, and it saved a ton of manual tracking time. So yeah, if you want both the test name and explicit params, pytest_collection_finish is a good middle ground between simple printing and full reporting.
Yeah, and if you want to take it even further especially in CI or heavy data-driven setups it’s worth turning this into a small internal plugin. Same idea: hook into pytest_collection_finish, but instead of printing, serialize everything into JSON/CSV.
def pytest_collection_finish(session):
data = []
for item in session.items:
params = getattr(item, "callspec", None)
data.append({
"test": item.nodeid,
"params": params.params if params else None
})
# write `data` to file here
We use this to review parameter coverage before running thousands of tests. That way, we can detect missing combinations early, skip expensive runs, or even show dashboards.
Long story short once you realize how much info pytest_collection_finish gives you post-collection, it becomes a goldmine for reporting and analysis."