Package: pytest-allure-adaptor
Allure Pytest AdaptorThis repository contains a plugin forpy.testwhich automatically prepares input data used to generateAllure Report.Note:this plugin currently supports only Allure 1.4.x series.Installation and Usagepy.test--alluredir[path_to_report_dir]# WARNING [path_to_report_dir] will be purged at first runThis plugin gets automatically connected topy.testviaentry pointif installed.Connecting to IDE:pytest_plugins='allure.pytest_plugin',\Allure FeaturesAttachmentsTo attach some content to test report:importalluredeftest_foo():allure.attach('my attach','Hello, World')StepsTo divide a test into steps:importpytestdeftest_foo():withpytest.allure.step('step one'):# do stuffwithpytest.allure.step('step two'):# do more stuffCan also be used as decorators. By default step name is generated from method name: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()isnotNoneSteps can also be used without pytest. In that case instead ofpytest.allure.stepsimply useallure.step:importallure@allure.step('some operation')defdo_operation():# do stuffallure.stepdecorator supports step name formatting with function parameters:importallure@allure.step('some operation for bar={0}')defdo_operation(bar):# do stuffdeftest_foo():assertdo_operation('abcdef')The step in the latter case will have namesome operation for bar=abcdef.
Formatting is done via python’s built-instring.formatand supports it’s options.
Arguments are passed toformatmethod in the same way they are passed to the decorated function.Steps support is limited when used with fixtures.SeverityAny test, class or module can be marked with different severity: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):passTo run tests with concrete priority:py.test my_tests/ --allure_severities=critical,blockerIssuesIssues can be set for test.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):passTest casesTest cases links can be set for test also.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):passFeatures & StoriesFeature and Story can be set for test.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):passTo run tests by Feature or Story:py.test my_tests/ --allure_features=feature1,feature2py.test my_tests/ --allure_features=feature1,feature2 --allure_stories=story1,story2Environment ParametersYou can provide test environment parameters such as report name, browser or test server address to allure test report.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)assertcountryMore details about allure environment you can know fromdocumentation.DevelopmentUseallure.common.AllureImplclass to bind your logic to this adapter.