Pytest 运行遇到 AttributeError: ‘str‘ object has no attribute ‘iter_parents‘

问题描述:

使用 Pytest 工具运行测试用例,出现 ERROR。如下图所示:

_________________________ ERROR at setup of test_card _________________________

self = <allure_pytest.listener.AllureListener object at 0x000001DEE43DAFD0>
item = <Function test_card>

    @pytest.hookimpl(hookwrapper=True)
    def pytest_runtest_setup(self, item):
        if not self._cache.get(item.nodeid):
            uuid = self._cache.push(item.nodeid)
            test_result = TestResult(name=item.name, uuid=uuid, start=now(), stop=now())
            self.allure_logger.schedule_test(uuid, test_result)
        yield
>       self._update_fixtures_children(item)

..\..\..\xShopvenv\lib\site-packages\allure_pytest\listener.py:88: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
..\..\..\xShopvenv\lib\site-packages\allure_pytest\listener.py:63: in _update_fixtures_children
    for fixturedef in _test_fixtures(item):

_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

item = <Function test_card>

    def _test_fixtures(item):
        fixturemanager = item.session._fixturemanager
        fixturedefs = []
    
        if hasattr(item, "_request") and hasattr(item._request, "fixturenames"):
            for name in item._request.fixturenames:
>               fixturedefs_pytest = fixturemanager.getfixturedefs(name, item.nodeid)
E               AttributeError: 'str' object has no attribute 'iter_parents'

..\..\..\xShopvenv\lib\site-packages\allure_pytest\listener.py:291: AttributeError

通过 Allure 报告查看用例执行结果:Broken。如下图所示:

通过查看 Overview 用例执行日志:

 AttributeError: 'str' object has no attribute 'iter_parents'
     if hasattr(item, "_request") and hasattr(item._request, "fixturenames"):
            for name in item._request.fixturenames:
>               fixturedefs_pytest = fixturemanager.getfixturedefs(name, item.nodeid)
E               AttributeError: 'str' object has no attribute 'iter_parents'
 

解决方案:

Pytest 8.2.0 和 8.1.0 的几个版本会破坏 allure 的 listener 导致虚拟机上执行报错,就是版本不兼容,需把pytest 回退到8.0.2就不报错啦!

通过 pip install pytest==8.0.2 安装之后重新执行测试用例,PASSED。

  • 34
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值