在pytest-allure中,有一种方法可以在我将其设置后获取当前的测试描述
allure.dynamic.description("""blah blah""")
寻找类似的东西
description = pytest.xxx or request.node.xxx ....
我正试图更好地解释我的需求。每个测试在关闭之前都会调用一个函数,并且它需要知道testdescription的值。我不想将其保存在变量中并传递给函数。我会通过诱人的变量来获取它。
@allure.title("MYTITLE")
def test_A1(self):
allure.dynamic.description("""MYDESC""")
...
myfunct()
def myfunct():
testdescription = ???
...
message: "Test done " + testdescription
smtpObj.sendmail(sender, receivers, message)
答案 0 :(得分:1)
查看allure_pytest
插件源,您可以从存储信息的插件管理器中获取正确的插件对象:
import allure
from allure_commons._core import plugin_manager
from allure_pytest.listener import AllureListener
@allure.title("MYTITLE")
def test_A1(request):
allure.dynamic.description("""MYDESC""")
myfunct()
def myfunct():
plugin = next(p for p in plugin_manager.get_plugins() if isinstance(p, AllureListener))
testdescription = plugin.allure_logger.get_test(None).description
...
但是,请注意该API不是公开的(并且看起来它不是公开的),因此请注意AllureListener
的实现中的更改,这些更改很容易破坏myfunct
。 / p>