py.test生成诱惑XML报告的插件

pytest-allure-adaptor的Python项目详细描述


诱惑Pytest适配器

Join the chat at https://gitter.im/allure-framework/allure-coreBuild StatusRelease StatusDownloads

此存储库包含用于py.test的插件,该插件自动准备用于生成Allure Report的输入数据。 注意:此插件当前仅支持allure 1.4.x系列。

安装和使用

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类将逻辑绑定到此适配器。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java RestTemplate到elasticsearch 6.7.0搜索>错误请求   java如何在OpenGL中对半透明三角形排序?   java如何将Pentaho6.0连接到HadoopHive   java更改图像视图大小   SQL查询在TOAD中运行良好,但在java代码中则不行   java需要根据事件发送HTTP请求   java HTMLUnit在javascript异常上挂起/无限循环   java阵列访问如何影响性能?   使用回滚时不引发异常的java事务测试方法   java如何在最近屏幕后返回到上一个活动   Java泛型函数返回声明   java从二进制文件读取   使用java泛型扩展接口还是糟糕的设计?   java是否将日历设置为特定日期?   java如何在鼠标悬停在一个矩形上时为其指定颜色?