Setting up a Pytest automated tests project

Setting up a Pytest automated tests project

This article is part of a series of blog posts for Streamlining test automation with TestRail, which aim to guide you through centralizing your test automation efforts in TestRail, as per the diagram below.

yRKAcljIqrwgc8 Fn7B8jGcBRmAT0dzaZN7bg9Jed9viBqDcvEzUoKe2Sa2O4wQ sazU5dP5ii4kfg 5iUHj8zi2pSEgTVAiSbO4TSrLG4Bq XzbEw097KJvl79uHOPZuPcvNQuwZ5RyuBQAstb06gQ

You can use dozens of different test automation frameworks to automate your test cases and each framework has its own characteristics and can be specialized in one or more types of testing. For this particular workflow, our only requirement is that the framework can generate a JUnit style report that we can use to upload our test results to TestRail. In our example, we’ll be using Pytest, a Python testing framework that makes it easy to write small, readable tests, and can scale to support complex functional testing for applications and libraries.

By the end of this article, you should be able to achieve steps 2 and 3 on the diagram, with the caveat of being on your local machine instead of Jenkins, but that is part of the process to achieve our end goal, so let’s keep it simple for now.

Setting up your local environment

To install and run a simple Pytest project, all you need is Python to get started. To install Python on your local machine, we recommend you download the Python 3.10.x distribution that matches your operating system and follow the install wizard instructions. To make sure the install was successful, try executing the commands python --version and pip --version from your command line and they should output their versions.

lbBiRRLqlHzsLFLMttm7ZQKd5gJdQICzKUEzHbZE4 h4kcEM aQew38ECWk7ZteeF8YpgFSNi6QVcr5UhPH7T6ddRqIRbrf9CBwIhiRS4LQ6gbErrqsgHaEB5KfgReVHX9hkDiGd3IRDKMrw4drbODQ

Installing and running the sample Pytest project

We have a simple sample project you can clone or download from our Automation Frameworks Integration GitHub repository. The test files live in the tests folder and, by opening the test_sum.py file, you can see very simple tests that add numbers and assert the expected result.

import pytest

def test_sum_two_numbers():
    assert 1 + 1 == 2

def test_sum_two_decimals():
    assert 0.8 + 0.3 == 1.2

@pytest.mark.parametrize("test_input,expected", [("3+5", 8), ("2+4", 6)])
def test_sum_multiple_numbers(test_input, expected):
    assert eval(test_input) == expected

To install the project, you simply need to run the command below on your preferred terminal. If you open the requirements.txt file, you’ll notice that the only dependency on this project is actually Pytest, so that’s all you will be installing.

$ pip install -r "requirements.txt"

Finally, to run the tests, execute the command below on your terminal and you should see the execution output in real-time, similar to the image below.

$ pytest "./tests"

vQey2Dwea0Ed87m6xdZjTRFJQIKpQ1KMLNP377i3im56WQi49krfDhVZIRdHZq DQ0ee3I6lq pxmuuCjzgw5W9TVqF9vwderJF Xkvajp148hZfB8DE9maXfOsddL5Q nOOVpL2walhZQS9vDTLQOM

Final result

You have just set up and executed your automated tests project on your local machine and you can execute it as often as you wish and customize it to your needs. The image below depicts the workflow you have achieved so far.

OjLr0YF P9hbmvXIfiAyzgmJit05e5Utrne2b9KCH4pM jR6Grsb7luRotfFbjoQOP2yaAJfnB5i DcFqZtiCpyYMT6FiI0DobQyViyD5sDzcB3rJraMKHCS3P9JOKbyvl45PELajtE1ovmBl5vjrIs

There are a few downsides to only running automated tests on your local machine. One of them is that they may become dependent on your own system configuration and the same execution may be difficult to reproduce on a different machine. Another downside is that the results won’t be visible to others in your organization. To circumvent these two pitfalls, you should use a CI tool, such as Jenkins, to orchestrate the execution of your automated tests in a consistent fashion and publish your test results.

To get to know how to configure Jenkins to execute your automated tests, please see the article referring to step 2 in this series of blog posts – Orchestrating an automated tests project with Jenkins as your CI tool.

In This Article:

Try a 30-day trial of TestRail today!

Share this article

Other Blogs

Why Test Visibility Breaks Down in Azure DevOps Workflows
Announcement, Integrations, TestRail

Why Test Visibility Breaks Down in Azure DevOps Workflows

Last updated: April 2026 · Author: Patrícia Mateus, TestRail TL;DR Azure DevOps teams lose test visibility because their test management tool and their development workflow live in separate systems. Test coverage, run results, and linked test cases do not surf...
Tracking and Reporting Flaky Tests with TestRail
Agile, Automation, Continuous Delivery, Software Quality

Tracking and Reporting Flaky Tests with TestRail

If you’ve ever dealt with flaky tests, you know how frustrating they can be. These tests seem to fail for no reason—one moment, they’re working perfectly, and the next, they’re not. Flaky tests can undermine your team’s confidence in your test suite and slow e...
AI in Test Automation: What Works Today and What QA Teams Should Expect Next
Automation, Artificial Intelligence (AI)

AI in Test Automation: What Works Today and What QA Teams Should Expect Next

Test automation was supposed to reduce manual effort. For many teams, it created a different maintenance problem. Oftentimes, automation suites grow faster than teams can maintain them, minor application changes break UI scripts, and QA engineers spend more ti...