pytest-github-actions-annotate-failures
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
- breaking Version 0.4.0 and later require Python >=3.10 and Pytest >=7.0.0. Older Python or Pytest versions are not supported and will likely lead to installation or runtime errors.
- gotcha If your tests are located in a subdirectory relative to the repository root (e.g., `src/tests/`), GitHub Actions may not correctly link annotations to the source files.
- breaking As of version 0.4.0, when `pytest-github-actions-annotate-failures` is used in conjunction with `pytest-rerunfailures`, only the *final* test failure is annotated. In previous versions (0.3.0 and older), annotations were added for all failed runs, including intermediate reruns.
Install
-
pip install pytest-github-actions-annotate-failures
Quickstart
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.