py.test生成诱惑XML报告的插件
pytest-allure-adaptor的Python项目详细描述
安装和使用
py.test--alluredir[path_to_report_dir]# WARNING [path_to_report_dir] will be purged at first run
如果已安装,此插件将通过entry point自动连接到py.test。
连接到IDE:
pytest_plugins='allure.pytest_plugin',\
诱惑特征
附件
在测试报告中附加一些内容:
importalluredeftest_foo():allure.attach('my attach','Hello, World')
步骤
将测试分为几个步骤:
importpytestdeftest_foo():withpytest.allure.step('step one'):# do stuffwithpytest.allure.step('step two'):# do more stuff
也可以用作装饰。默认情况下,步骤名由方法名生成:
importpytest@pytest.allure.stepdefmake_test_data_foo():# do stuffdeftest_foo():assertmake_some_data_foo()isnotNone@pytest.allure.step('make_some_data_foo')defmake_some_data_bar():# do another stuffdeftest_bar():assertmake_some_data_bar()isnotNone
步骤也可以在不使用pytest的情况下使用。在这种情况下,只需使用allure.step:
importallure@allure.step('some operation')defdo_operation():# do stuff
allure.stepdecorator支持用函数参数格式化步骤名:
importallure@allure.step('some operation for bar={0}')defdo_operation(bar):# do stuffdeftest_foo():assertdo_operation('abcdef')
后一种情况下的步骤将具有名称some operation for bar=abcdef。 格式化是通过python的内置string.format完成的,并且支持它的选项。 参数传递给format方法的方式与传递给修饰函数的方式相同。
与固定装置一起使用时,台阶支撑受到限制。
严重性
任何测试、类或模块都可以标记为不同的严重性:
importpytest@pytest.allure.severity(pytest.allure.severity_level.MINOR)deftest_minor():assertFalse@pytest.allure.severity(pytest.allure.severity_level.CRITICAL)classTestBar:# will have CRITICAL prioritydeftest_bar(self):pass# will have BLOCKER priority via a short-cut decorator@pytest.allure.BLOCKERdeftest_bar(self):pass
以具体优先级运行测试:
py.test my_tests/ --allure_severities=critical,blocker
问题
可以为测试设置问题。
importpytest@pytest.allure.issue('http://jira.lan/browse/ISSUE-1')deftest_foo():assertFalseimportallure@allure.issue('http://jira.lan/browse/ISSUE-2')classTestBar:# test will have ISSUE-2, ISSUE-3 and ISSUE-4 label@allure.issue('http://jira.lan/browse/ISSUE-3')deftest_bar1(self):# You can use this feature like a function inside the testallure.dynamic_issue('http://jira.lan/browse/ISSUE-4')pass# test will have only ISSUE-2 labeldeftest_bar2(self):pass
测试用例
也可以为测试设置测试用例链接。
importpytest@pytest.allure.testcase('http://my.tms.org/TESTCASE-1')deftest_foo():assertFalseimportallure@allure.testcase('http://my.tms.org/browse/TESTCASE-2')classTestBar:# test will have TESTCASE-2 and TESTCASE-3 label@allure.testcase('TESTCASE-3')deftest_bar1(self):pass# test will have only TESTCASE-2 labeldeftest_bar2(self):pass
功能和故事
特色和故事可以设置为测试。
importallure@allure.feature('Feature1')@allure.story('Story1')deftest_minor():assertFalse@allure.feature('Feature2')@allure.story('Story2','Story3')@allure.story('Story4')classTestBar:# will have 'Feature2 and Story2 and Story3 and Story4'deftest_bar(self):pass
按功能或故事运行测试:
py.test my_tests/ --allure_features=feature1,feature2 py.test my_tests/ --allure_features=feature1,feature2 --allure_stories=story1,story2
环境参数
您可以提供测试环境参数,例如报表名称、浏览器或测试服务器地址来吸引测试报表。
importallureimportpytestdefpytest_configure(config):allure.environment(report='Allure report',browser=u'Я.Браузер')@pytest.fixture(scope="session")defapp_host_name():host_name="my.host.local"allure.environment(hostname=host_name)returnhost_name@pytest.mark.parametrize('country',('USA','Germany',u'Россия',u'Япония'))deftest_minor(country):allure.environment(country=country)assertcountry
更多关于诱惑环境的细节,你可以从documentation知道。
开发
使用allure.common.AllureImpl类将逻辑绑定到此适配器。