2

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

当我使用 xdist 并行运行测试时遇到问题,如果我以串行方式运行测试,则没有这样的问题:

如果只有 1 次失败或没有失败,则能够生成诱惑报告

当一次测试运行出现多个失败时,无法生成诱惑报告、堆栈跟踪和错误信息:

 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'
4

1 回答 1

0

我遇到了同样的问题:

  • Python 2.7.10
  • 诱惑-pytest-适配器 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 插件交互的方式。结合起来,它们将失败输出作为 dict 而不是类对象发送,pytest 失败ReprTraceback类使用它来处理失败输出数据。

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

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

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

我希望这是有帮助的。

于 2017-12-05T20:43:19.827 回答