Skip to content

Run tests against different package sets in parallel #2433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,21 @@ jobs:
CO_API_KEY: ${{ secrets.COHERE_API_KEY }}

test:
name: test on ${{ matrix.python-version }}
name: test ${{ matrix.packages }} on ${{ matrix.python-version }}
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
packages: [slim, standard, all-extras, lowest-versions, import-examples]
exclude:
- python-version: "3.9"
packages: lowest-versions
- python-version: "3.9"
packages: import-examples
- python-version: "3.10"
packages: import-examples
env:
UV_PYTHON: ${{ matrix.python-version }}
CI: true
Expand All @@ -154,34 +162,40 @@ jobs:

- run: mkdir .coverage

# run tests with just `pydantic-ai-slim` dependencies
- run: uv run --package pydantic-ai-slim coverage run -m pytest -n auto --dist=loadgroup
- name: test slim
run: cd pydantic_ai_slim && uv run --group dev coverage run -m pytest -n auto --dist=loadgroup && cd ..
if: matrix.packages == 'slim'
env:
COVERAGE_FILE: .coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }}-slim
COVERAGE_FILE: ../.coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }}-slim

- run: uv run coverage run -m pytest -n auto --dist=loadgroup
- name: test standard
run: uv run --group dev coverage run -m pytest -n auto --dist=loadgroup
if: matrix.packages == 'standard'
env:
COVERAGE_FILE: .coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }}-standard

- run: uv run --all-extras coverage run -m pytest -n auto --dist=loadgroup
- name: test all extras
run: uv run --group dev --all-extras coverage run -m pytest -n auto --dist=loadgroup
if: matrix.packages == 'all-extras'
env:
COVERAGE_FILE: .coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }}-all-extras

- run: uv run --all-extras python tests/import_examples.py

# this must run last as it modifies the environment!
- name: test lowest versions
if: matrix.python-version != '3.9'
if: matrix.packages == 'lowest-versions'
run: |
unset UV_FROZEN
uv run --all-extras --resolution lowest-direct coverage run -m pytest -n auto --dist=loadgroup
uv run --group dev --all-extras --resolution lowest-direct coverage run -m pytest -n auto --dist=loadgroup
env:
COVERAGE_FILE: .coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }}-lowest-versions

- name: test import examples
if: matrix.packages == 'import-examples'
run: uv run --all-extras python tests/import_examples.py

- name: store coverage files
uses: actions/upload-artifact@v4
with:
name: coverage-${{ matrix.python-version }}
name: coverage-${{ matrix.python-version }}-${{ matrix.packages }}
path: .coverage
include-hidden-files: true

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

.PHONY: install
install: .uv .pre-commit .deno ## Install the package, dependencies, and pre-commit for local development
uv sync --frozen --all-extras --all-packages --group lint --group docs
uv sync --frozen --all-extras --all-packages --group dev --group lint --group docs
pre-commit install --install-hooks

.PHONY: install-all-python
Expand Down
20 changes: 19 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,25 @@ members = [
]

[dependency-groups]
# dev dependencies are defined in `pydantic-ai-slim/pyproject.toml` to allow for minimal testing
dev = [
"anyio>=4.5.0",
"asgi-lifespan>=2.1.0",
"devtools>=0.12.2",
"coverage[toml]>=7.10.2",
"dirty-equals>=0.9.0",
"duckduckgo-search>=7.0.0",
"inline-snapshot>=0.19.3",
"pytest>=8.3.3",
"pytest-examples>=0.0.14",
"pytest-mock>=3.14.0",
"pytest-pretty>=1.3.0",
"pytest-recording>=0.13.2",
"diff-cover>=9.2.0",
"boto3-stubs[bedrock-runtime]",
"strict-no-cover @ git+https://github.com/pydantic/strict-no-cover.git@7fc59da2c4dff919db2095a0f0e47101b657131d",
"pytest-xdist>=3.6.1",
"coverage-enable-subprocess>=0.1.0",
]
lint = ["mypy>=1.11.2", "pyright>=1.1.390", "ruff>=0.6.9"]
docs = [
"pydantic-ai[a2a]",
Expand Down
24 changes: 10 additions & 14 deletions tests/import_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,17 @@
"""

import os
import sys
from pathlib import Path

if sys.version_info < (3, 11):
print('Skipping import_examples.py because it requires Python 3.11+')
else:
os.environ.update(OPENAI_API_KEY='fake-key', GEMINI_API_KEY='fake-key', GROQ_API_KEY='fake-key')
os.environ.update(OPENAI_API_KEY='fake-key', GEMINI_API_KEY='fake-key', GROQ_API_KEY='fake-key')

examples_dir = Path(__file__).parent.parent / 'examples' / 'pydantic_ai_examples'
assert examples_dir.is_dir(), f'No examples directory found at {examples_dir}'
count = 0
for example in examples_dir.glob('*.py'):
print(f'Importing {example.stem}...')
__import__(f'pydantic_ai_examples.{example.stem}')
count += 1
examples_dir = Path(__file__).parent.parent / 'examples' / 'pydantic_ai_examples'
assert examples_dir.is_dir(), f'No examples directory found at {examples_dir}'
count = 0
for example in examples_dir.glob('*.py'):
print(f'Importing {example.stem}...')
__import__(f'pydantic_ai_examples.{example.stem}')
count += 1

print(f'Imported {count} examples')
assert count > 5, 'No examples found'
print(f'Imported {count} examples')
assert count > 5, 'No examples found'
84 changes: 40 additions & 44 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading