首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >pytest-xdist导致样式:'dict‘对象没有’AttributeError‘属性

pytest-xdist导致样式:'dict‘对象没有’AttributeError‘属性
EN

Stack Overflow用户
提问于 2017-10-25 04:52:20
回答 1查看 542关注 0票数 2

目前使用的是allure- pytest -adaptor 1.7.8、pytest 3.2.1和pytest-xdist 1.20.0

当我使用xdist并行运行测试时出现问题,如果我以串行方式运行所有测试,则不会出现这样的问题:

如果只有1个故障或没有故障,则可以生成诱饵报告

当测试运行中有多个失败时,无法生成引诱报告、堆栈跟踪和错误消息:

代码语言:javascript
复制
 File "/data/jenkins/workspace/Pilot_WebUI_Python_Functional_Test/automated-tests/.tox/jenkins-webui/bin/py.test", line 11, in <module>
    sys.exit(main())
  File "/data/jenkins/workspace/Pilot_WebUI_Python_Functional_Test/automated-tests/.tox/jenkins-webui/lib/python3.5/site-packages/_pytest/config.py", line 58, in main
    return config.hook.pytest_cmdline_main(config=config)
  File "/data/jenkins/workspace/Pilot_WebUI_Python_Functional_Test/automated-tests/.tox/jenkins-webui/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 745, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "/data/jenkins/workspace/Pilot_WebUI_Python_Functional_Test/automated-tests/.tox/jenkins-webui/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 339, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/data/jenkins/workspace/Pilot_WebUI_Python_Functional_Test/automated-tests/.tox/jenkins-webui/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 334, in <lambda>
    _MultiCall(methods, kwargs, hook.spec_opts).execute()
  File "/data/jenkins/workspace/Pilot_WebUI_Python_Functional_Test/automated-tests/.tox/jenkins-webui/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 614, in execute
    res = hook_impl.function(*args)
  File "/data/jenkins/workspace/Pilot_WebUI_Python_Functional_Test/automated-tests/.tox/jenkins-webui/lib/python3.5/site-packages/_pytest/main.py", line 139, in pytest_cmdline_main
    return wrap_session(config, _main)
  File "/data/jenkins/workspace/Pilot_WebUI_Python_Functional_Test/automated-tests/.tox/jenkins-webui/lib/python3.5/site-packages/_pytest/main.py", line 133, in wrap_session
    exitstatus=session.exitstatus)
  File "/data/jenkins/workspace/Pilot_WebUI_Python_Functional_Test/automated-tests/.tox/jenkins-webui/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 745, in __call__
    return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
  File "/data/jenkins/workspace/Pilot_WebUI_Python_Functional_Test/automated-tests/.tox/jenkins-webui/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 339, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/data/jenkins/workspace/Pilot_WebUI_Python_Functional_Test/automated-tests/.tox/jenkins-webui/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 334, in <lambda>
    _MultiCall(methods, kwargs, hook.spec_opts).execute()
  File "/data/jenkins/workspace/Pilot_WebUI_Python_Functional_Test/automated-tests/.tox/jenkins-webui/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 613, in execute
    return _wrapped_call(hook_impl.function(*args), self.execute)
  File "/data/jenkins/workspace/Pilot_WebUI_Python_Functional_Test/automated-tests/.tox/jenkins-webui/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 250, in _wrapped_call
    wrap_controller.send(call_outcome)
  File "/data/jenkins/workspace/Pilot_WebUI_Python_Functional_Test/automated-tests/.tox/jenkins-webui/lib/python3.5/site-packages/_pytest/terminal.py", line 406, in pytest_sessionfinish
    outcome.get_result()
  File "/data/jenkins/workspace/Pilot_WebUI_Python_Functional_Test/automated-tests/.tox/jenkins-webui/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 279, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/data/jenkins/workspace/Pilot_WebUI_Python_Functional_Test/automated-tests/.tox/jenkins-webui/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 265, in __init__
    self.result = func()
  File "/data/jenkins/workspace/Pilot_WebUI_Python_Functional_Test/automated-tests/.tox/jenkins-webui/lib/python3.5/site-packages/_pytest/vendored_packages/pluggy.py", line 614, in execute
    res = hook_impl.function(*args)
  File "/data/jenkins/workspace/Pilot_WebUI_Python_Functional_Test/automated-tests/.tox/jenkins-webui/lib/python3.5/site-packages/allure/pytest_plugin.py", line 494, in pytest_sessionfinish
    self.impl._write_xml(f, s)
  File "/data/jenkins/workspace/Pilot_WebUI_Python_Functional_Test/automated-tests/.tox/jenkins-webui/lib/python3.5/site-packages/allure/common.py", line 254, in _write_xml
    xmlfied.toxml(),
  File "/data/jenkins/workspace/Pilot_WebUI_Python_Functional_Test/automated-tests/.tox/jenkins-webui/lib/python3.5/site-packages/allure/rules.py", line 129, in toxml
    manys = sum([[(m[0], v) for v in m[1]] for m in entries(Many)], [])
  File "/data/jenkins/workspace/Pilot_WebUI_Python_Functional_Test/automated-tests/.tox/jenkins-webui/lib/python3.5/site-packages/allure/rules.py", line 123, in entries
    for (name, rule) in items
  File "/data/jenkins/workspace/Pilot_WebUI_Python_Functional_Test/automated-tests/.tox/jenkins-webui/lib/python3.5/site-packages/allure/rules.py", line 124, in <listcomp>
    if isinstance(rule, clazz) and rule.check(getattr(self, name))]
  File "/data/jenkins/workspace/Pilot_WebUI_Python_Functional_Test/automated-tests/.tox/jenkins-webui/lib/python3.5/site-packages/allure/rules.py", line 109, in value
    values = super(WrappedMany, self).value(name, what)
  File "/data/jenkins/workspace/Pilot_WebUI_Python_Functional_Test/automated-tests/.tox/jenkins-webui/lib/python3.5/site-packages/allure/rules.py", line 103, in value
    return [self.rule.value(name, x) for x in what]
  File "/data/jenkins/workspace/Pilot_WebUI_Python_Functional_Test/automated-tests/.tox/jenkins-webui/lib/python3.5/site-packages/allure/rules.py", line 103, in <listcomp>
    return [self.rule.value(name, x) for x in what]
  File "/data/jenkins/workspace/Pilot_WebUI_Python_Functional_Test/automated-tests/.tox/jenkins-webui/lib/python3.5/site-packages/allure/rules.py", line 92, in value
    return what.toxml()
  File "/data/jenkins/workspace/Pilot_WebUI_Python_Functional_Test/automated-tests/.tox/jenkins-webui/lib/python3.5/site-packages/allure/rules.py", line 128, in toxml
    nested = entries(Nested)
  File "/data/jenkins/workspace/Pilot_WebUI_Python_Functional_Test/automated-tests/.tox/jenkins-webui/lib/python3.5/site-packages/allure/rules.py", line 123, in entries
    for (name, rule) in items
  File "/data/jenkins/workspace/Pilot_WebUI_Python_Functional_Test/automated-tests/.tox/jenkins-webui/lib/python3.5/site-packages/allure/rules.py", line 124, in <listcomp>
    if isinstance(rule, clazz) and rule.check(getattr(self, name))]
  File "/data/jenkins/workspace/Pilot_WebUI_Python_Functional_Test/automated-tests/.tox/jenkins-webui/lib/python3.5/site-packages/allure/rules.py", line 92, in value
    return what.toxml()
  File "/data/jenkins/workspace/Pilot_WebUI_Python_Functional_Test/automated-tests/.tox/jenkins-webui/lib/python3.5/site-packages/allure/rules.py", line 126, in toxml
    elements = entries(Element)
  File "/data/jenkins/workspace/Pilot_WebUI_Python_Functional_Test/automated-tests/.tox/jenkins-webui/lib/python3.5/site-packages/allure/rules.py", line 123, in entries
    for (name, rule) in items
  File "/data/jenkins/workspace/Pilot_WebUI_Python_Functional_Test/automated-tests/.tox/jenkins-webui/lib/python3.5/site-packages/allure/rules.py", line 124, in <listcomp>
    if isinstance(rule, clazz) and rule.check(getattr(self, name))]
  File "/data/jenkins/workspace/Pilot_WebUI_Python_Functional_Test/automated-tests/.tox/jenkins-webui/lib/python3.5/site-packages/allure/rules.py", line 80, in value
    return element_maker(self.name or name, self.namespace)(legalize_xml(unicodify(what)))
  File "/data/jenkins/workspace/Pilot_WebUI_Python_Functional_Test/automated-tests/.tox/jenkins-webui/lib/python3.5/site-packages/allure/utils.py", line 126, in unicodify
    return text_type(something)  # @UndefinedVariable
  File "/data/jenkins/workspace/Pilot_WebUI_Python_Functional_Test/automated-tests/.tox/jenkins-webui/lib/python3.5/site-packages/_pytest/_code/code.py", line 694, in __str__
    s = self.__unicode__()
  File "/data/jenkins/workspace/Pilot_WebUI_Python_Functional_Test/automated-tests/.tox/jenkins-webui/lib/python3.5/site-packages/_pytest/_code/code.py", line 704, in __unicode__
    self.toterminal(tw)
  File "/data/jenkins/workspace/Pilot_WebUI_Python_Functional_Test/automated-tests/.tox/jenkins-webui/lib/python3.5/site-packages/_pytest/_code/code.py", line 735, in toterminal
    element[0].toterminal(tw)
  File "/data/jenkins/workspace/Pilot_WebUI_Python_Functional_Test/automated-tests/.tox/jenkins-webui/lib/python3.5/site-packages/_pytest/_code/code.py", line 764, in toterminal
    if entry.style == "long":
AttributeError: 'dict' object has no attribute 'style'
EN

回答 1

Stack Overflow用户

发布于 2017-12-06 04:43:20

我在使用以下命令时遇到了同样的问题:

  • Python 2.7.10
  • allure-pytest-adaptor 1.7.9
  • pytest 3.0.0
  • pytest-xdist 1.20.0

我找到了这个链接,但目前无法升级插件和我的Python版本:

https://github.com/pytest-dev/pytest/issues/2811

如果上面的方法对你很有效,但是如果你发现自己需要一个补丁来解决你所遇到的问题,我有一个可能有用的补丁。

问题(我认为)是xdist失败与pytest和pytest-allure adaptor插件交互的方式。它们组合在一起,将失败输出作为字典而不是类对象发送,pytest failure ReprTraceback类使用类对象来处理失败输出数据。

这可以通过使用__dict__对象将测试报告属性存储在对象中来解决。事实证明,作者已经部分解决了这一问题。我只是更新了allure pytest_plugin.py中的现有方法,以公开所有必要的报告数据,然后用更新后的方法替换了预期的报告终结器条件。我有一个来自这个插件的分支版本的补丁:

https://github.com/weeksghost/allure-python/tree/parallel-test-results

我确信有更好的方法来处理这个问题,但是看起来这个版本的魅力项目不再被支持,而是支持一个更新的版本,我觉得这是一个非常棒的升级。我将升级,但以我自己的速度,因此黑客。

我希望这能对你有所帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46919802

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档