In this article, I describe how to integrate Tesults with pytest for reporting, specifically using pytest conftest files. I will assume you already have testing setup with pytest. The official pytest documentation is located here. Let’s get started integrating Tesults into our test automation project. Here are the details for Tesults and pytest step by step.

Step 1 – Sign Up

Tesults is a web-based (cloud hosted) app which means that unlike Allure or ExtentReports there is nothing to setup with respect to infrastructure or software but it does require signing up. Go to Tesults and sign up.

Step 2 – Create a Project

After signing up, login and click the settings (middle) icon from the top right menu bar.

This opens up the settings/configuration. You need to create at least one project to start reporting results. Click create a project and name the project.

Finish creating the project by selecting a free or paid plan. A token is provided:

You must copy this token because it is needed later in the code to upload results from pytest.

Step 3 – Add a conftest.py file to the pytest test directory

Tesults provides documentation for reporting results with Python here and for pytest specifically here.

I will outline the process here. Install the Tesults Python API library using pip:

pip install tesults

Next, create a new python file called conftest.py. This is considered a ‘local plug-in’ by pytest. For more detailed information about conftest.py see this link.

The conftest.py can contain ‘hook’ functions that pytest automatically runs as your tests run (the file must have the name conftest.py for pytest to recognize it). To record results and upload them to Tesults we need to implement two hook functions: pytest_runtest_protocol and pytest_unconfigure both documented here.

Rather than write custom code you can copy and paste the conftest.py from Tesults. You need to replace the value of ‘token’ in line 8 with the token you generated on creating your project. You should not have to edit anything else.

You can place the conftest.py in a specific test directory or if you want to upload results across multiple test directories, move the conftest.py to the higher level directory.

I mentioned that the conftest.py only needs to implement two functions and this does that, but there are also additional helper functions in the code above that take care of automatically reporting complete test details.

This mostly just works automatically, the only thing you have to consider is that if you want a test description to be uploaded include this line above each of your test functions:

@pytest.mark.description(“your test description”)

Also for parameterized test cases, add something similar to:

@pytest.mark.parametrize((“test_input”,”expected”), [(“3+5”, 8),(“2+4”, 6),(“6*9”, 42),])

That completes the integration.  Now run the tests.

Step 4 – Run the tests and generate the report on Tesults

Run the tests by running tests the same way you always do in pytest:

python -m pytest

As can be seen in the output the upload to Tesults has been successful. Now we can go back to the web browser and view the results at https://www.tesults.com/results

Clicking on a test case displays details:

You can see the failure reason and see that the log for the test is also available.

If you upload screen captures they are shown in preview in the test case.

The view above becomes useful when several test runs have occurred because you can see new and continuing failures.

Note: This article is written in collaboration with Ajeet Dhaliwal.
Thanks.