DEV Community

Sergio Alberto Colque Ponce
Sergio Alberto Colque Ponce

Posted on

πŸš€ GitHub Actions as a Testing Management Tool: Real-world CI/CD with Python

🎯 Introduction

In the world of modern software development, automated testing and continuous integration are no longer optional β€” they’re essential. That's where GitHub Actions shines: a powerful CI/CD tool built directly into GitHub.

In this article, we’ll explore how GitHub Actions works as a Testing Management Tool, automate testing for a Python project, and demonstrate how to streamline code quality checks using real-world code examples.

βœ… A complete public repo accompanies this article: github.com/srg-cp/gh-actions-python-tests

🧰 What is GitHub Actions?
GitHub Actions is GitHub’s native CI/CD tool that lets you automate workflows across the development lifecycle: from testing and building to deployment.

Why use it as a Testing Management Tool?

  • Seamlessly integrates with your GitHub repo.
  • Supports all testing frameworks (pytest, unittest, etc.).
  • Automates testing on every push or PR.
  • Offers clear visibility via workflow status and logs.

πŸ“¦ Project Overview
We’ll use a simple Python project:

  • A module with a math function (calculator.py)
  • Unit tests using unittest (test_calculator.py)
  • A GitHub Actions workflow to run the tests automatically

πŸ“ Project structure:

gh-actions-python-tests/
β”‚
β”œβ”€β”€ calculator/
β”‚   └── calculator.py
β”œβ”€β”€ tests/
β”‚   └── test_calculator.py
β”œβ”€β”€ .github/
β”‚   └── workflows/
β”‚       └── test.yml
β”œβ”€β”€ requirements.txt
└── README.md

Enter fullscreen mode Exit fullscreen mode

πŸ§ͺ 1. The Python Code

calculator.py

def add(a, b):
    return a + b

def subtract(a, b):
    return a - b
Enter fullscreen mode Exit fullscreen mode

test_calculator.py

import unittest
from calculator.calculator import add, subtract

class TestCalculator(unittest.TestCase):

    def test_add(self):
        self.assertEqual(add(3, 2), 5)

    def test_subtract(self):
        self.assertEqual(subtract(10, 4), 6)

if __name__ == '__main__':
    unittest.main()
Enter fullscreen mode Exit fullscreen mode

requirements.txt

unittest2
Enter fullscreen mode Exit fullscreen mode

βš™οΈ 2. GitHub Actions Workflow

We’ll create a CI workflow to automatically install dependencies and run tests on each push or pull_request.

.github/workflows/test.yml

name: Python Unit Tests

on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout code
      uses: actions/checkout@v4

    - name: Set up Python
      uses: actions/setup-python@v5
      with:
        python-version: 3.11

    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -r requirements.txt

    - name: Run unit tests
      run: python -m unittest discover -s tests

Enter fullscreen mode Exit fullscreen mode

βœ… This will:

  • Trigger on push/PR
  • Use Python 3.11
  • Run tests with unittest

πŸ“Š 3. Workflow in Action
Once pushed to GitHub, go to the "Actions" tab to see:

  • Live logs of each CI run
  • Summary of passed/failed tests
  • Direct links to PRs or commits related to the run

This ensures that:

  • Developers are alerted to test failures immediately.
  • Every change is automatically validated.
  • Test coverage becomes part of the development process.

🌍 Real-world Examples from the Community

To reinforce the relevance of GitHub Actions as a testing management tool, here are some public repositories by developers using it with Python:

Repository: Description (Link)

  1. pallets/flask: Official Flask repository. Uses GitHub Actions to run tests with tox and multiple Python versions. πŸ”— GitHub
  2. tiangolo/fastapi: FastAPI framework by SebastiΓ‘n RamΓ­rez. Contains automated testing workflows. πŸ”— GitHub
  3. psf/requests: The famous HTTP library requests uses GitHub Actions to test on all major platforms. πŸ”— GitHub
  4. pytest-dev/pytest: The pytest testing framework runs all its test automation through GitHub Actions. πŸ”— GitHub
  5. kennethreitz/pipenv: Manages virtual environments and dependencies; runs tests with GitHub Actions. πŸ”— GitHub

These repositories show how powerful and widely adopted GitHub Actions has become for testing management in Python ecosystems.


🏁 Final Thoughts

GitHub Actions allows for rapid feedback, automated validation, and easy integration β€” making it a robust and developer-friendly Testing Management Tool.

πŸ”— Don’t forget to explore the repo here:
πŸ‘‰ Repo github

Top comments (0)