pytest-github-actions-annotate-failures

0.4.0 · active · verified Fri Apr 10

A pytest plugin designed to enhance GitHub Actions workflows by annotating failed tests directly in the pull request or commit view. It parses pytest output and generates GitHub workflow commands to create inline annotations for test failures, providing immediate feedback on problematic code lines. The project is actively maintained under the pytest-dev organization, with its latest version being 0.4.0.

Warnings

Install

Quickstart

This quickstart demonstrates how to set up `pytest-github-actions-annotate-failures` in a basic GitHub Actions workflow. Once installed and integrated, failed tests will automatically produce inline annotations in your GitHub pull requests or commit details, pointing directly to the line of code that caused the failure. No special command-line flags are typically needed for activation, as pytest discovers the plugin automatically upon installation.

mkdir my_project
cd my_project

# Create a test file
cat <<EOF > test_example.py
def test_passing():
    assert True

def test_failing():
    assert False
EOF

# Create GitHub Actions workflow file
mkdir -p .github/workflows
cat <<EOF > .github/workflows/ci.yml
name: Test with Annotations
on: [push, pull_request]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - name: Set up Python
      uses: actions/setup-python@v5
      with:
        python-version: '3.10'
    - name: Install dependencies
      run: pip install pytest pytest-github-actions-annotate-failures
    - name: Run tests with annotations
      run: pytest
EOF

# To see it in action, commit these files to a GitHub repository
# and push. The workflow will run and failed tests will show
# annotations in the 'Checks' or 'Actions' tab.

view raw JSON →