0
0
PyTesttesting~10 mins

Running PyTest in GitHub Actions - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test runs a simple PyTest test case inside a GitHub Actions workflow. It verifies that the test executes successfully and the assertion passes.

Test Code - PyTest
PyTest
import pytest

def test_addition():
    assert 2 + 3 == 5

# GitHub Actions workflow file (.github/workflows/python-test.yml):
# name: Python package
# on: [push]
# jobs:
#   build:
#     runs-on: ubuntu-latest
#     steps:
#     - uses: actions/checkout@v3
#     - name: Set up Python 3.12
#       uses: actions/setup-python@v4
#       with:
#         python-version: '3.12'
#     - name: Install dependencies
#       run: |
#         python -m pip install --upgrade pip
#         pip install pytest
#     - name: Run tests
#       run: |
#         pytest
Execution Trace - 6 Steps
StepActionSystem StateAssertionResult
1GitHub Actions workflow starts on push eventGitHub runner environment (ubuntu-latest) is ready-PASS
2Checkout repository code using actions/checkout@v3Test code and workflow files are available on runner-PASS
3Set up Python 3.12 environment using actions/setup-python@v4Python 3.12 is installed and active-PASS
4Install pytest using pippytest package is installed in the environment-PASS
5Run pytest command to execute test_additionpytest runs test_addition functionassert 2 + 3 == 5 is TruePASS
6PyTest reports test resultTest passed with no failuresTest summary shows 1 passed, 0 failedPASS
Failure Scenario
Failing Condition: The assertion in test_addition fails (e.g., assert 2 + 3 == 6)
Execution Trace Quiz - 3 Questions
Test your understanding
What does the GitHub Actions step 'actions/checkout@v3' do in this test?
AIt downloads the repository code to the runner
BIt installs Python on the runner
CIt runs the pytest tests
DIt uploads test results to GitHub
Key Result
Always include a simple test with a clear assertion to verify your test environment setup works correctly in CI pipelines like GitHub Actions.