def pytest_collection_modifyitems(session, items):
"""Add marker to test name, if test marked with `idempotent_id` marker.
If optional kwargs passed - test parameters should be a
superset of this kwargs to mark be applied.
Also kwargs can be passed as `params` argument.
"""
ids = defaultdict(list)
for item in items:
test_id = get_item_id(item)
ids[test_id].append(item)
if test_id is not None:
item.name += '[id-{}]'.format(test_id)
if session.config.option.check_idempotent_id:
errors = []
without_id = ids.pop(None, [])
if without_id:
errors += ["Tests without idempotent_id:"]
errors += [' ' + x.nodeid for x in without_id]
for test_id, items in ids.items():
if len(items) > 1:
errors += ["Single idempotent_id for many cases:"]
errors += [' ' + x.nodeid for x in items]
if errors:
print('')
print('\n'.join(errors))
pytest.exit('Errors with idempotent_id')
评论列表
文章目录