idempotent_id.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:stepler 作者: Mirantis 项目源码 文件源码
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')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号