问题描述:
使用 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。