📜 ⬆️ ⬇️

Connecting an Allure-reporter to an arbitrary python test framework

Automation needs human-readable test reports - what has been tested, what test steps, what result. To do this, there is a system for generating reports Allure .


Allure is supported by most well-known test frameworks, and for unknowns it requires writing a so-called adapter.


How to connect Allure in any arbitrary or no framework at all?


Using Allure consists of two independent steps:


  1. Generation of json-s containing all actions of the test, the so-called allure-results .


  2. Generate a report on the collected results (requires java8 and install the allure utility: https://bintray.com/qameta/generic/allure2 ). This item is the same for all types of frameworks due to the fact that allure-results is a fairly universal description of tests:


    allure generate /some_path_to/allure-results 

    Writing a full-fledged adapter for allure and integrating it into an arbitrary framework is somewhat laborious, so we will use the minimum possible set of actions in order to only illustrate the idea. The code below is a python adaptation of the ideas outlined in the report about the allure-lifecycle in Java, the original .



Install only the core of the allure-reporter:


 pip install allure-python-commons 

Let's write a simple test that generates allure-results:


 # -*- coding: utf-8 -*- import allure_commons from allure_commons.utils import now, uuid4 from allure_commons.reporter import AllureReporter from allure_commons.logger import AllureFileLogger from allure_commons.model2 import Status from allure_commons.model2 import TestResult from allure_commons.model2 import TestStepResult def check_some_thing(some): print ("Some is %s" % some) return some if __name__ == '__main__': print ("Start main") # Init allure allurelogdir = "reportsx" logger = AllureReporter() file_logger = AllureFileLogger(allurelogdir) allure_commons.plugin_manager.register(file_logger) # Start testcase case_uuid = uuid4() testcase = TestResult(uuid=case_uuid, fullName='Hello, Habr') logger.schedule_test(case_uuid, testcase) # TestStep allure_step = TestStepResult(name=', habrateststepname (   )', start=now()) current_step_uuid = uuid4() logger.start_step(None, current_step_uuid, allure_step) check_some_thing('something') # origial procedure for testing logger.stop_step(current_step_uuid, stop=now(), status=Status.PASSED) testcase.status = Status.PASSED logger.close_test(case_uuid) 

After launch, this code will generate the results in the "reports" folder


As you can see, the code for working with test steps (start_step and stop_step) perfectly fits the decorator pattern and should be implemented by it.


Arrange these code blocks on your test framework and collect fake tests with manual testing results, generate allure generate and you will receive a ready-made solution for unifying department reports.


')

Source: https://habr.com/ru/post/350480/


All Articles