pytest-item-dict
raw JSON → 1.1.2 verified Fri May 01 auth: no python
A pytest plugin that provides a hierarchical dict of session.items, enabling easy access to test items by node ID or custom keys. Current version 1.1.2, requires Python >=3.11. Released as needed.
pip install pytest-item-dict Common errors
error pytest_item_dict.item_dict() returns empty dict ↓
cause Called before pytest collects items.
fix
Run pytest with --collect-only or after a test session.
error ImportError: cannot import name 'item_dict' from 'pytest_item_dict' ↓
cause Wrong import path or older version.
fix
Use 'from pytest_item_dict import item_dict' and upgrade to >=1.0.0.
Warnings
gotcha item_dict() can only be called after pytest session has collected items, typically after a test run or --collect-only. ↓
fix Ensure pytest session has run before calling item_dict().
gotcha The hierarchical dict keys are based on node IDs; custom keys require modifying the plugin. ↓
fix Use node IDs as keys or extend the plugin for custom keys.
Imports
- item_dict wrong
from pytest_item_dict import get_item_dictcorrectfrom pytest_item_dict import item_dict
Quickstart
import pytest
from pytest_item_dict import item_dict
pytest.main(['-v', '--collect-only'])
# Access items via item_dict()
items = item_dict()
print(items.keys())