Skip to content

Commit d2595f3

Browse files
peterHoburgKludex
andauthored
Add make test-fast with xdist for local development (#1768)
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
1 parent a7cb6d5 commit d2595f3

File tree

6 files changed

+62
-25
lines changed

6 files changed

+62
-25
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ test: ## Run tests and collect coverage data
6363
uv run coverage run -m pytest
6464
@uv run coverage report
6565

66+
.PHONY: test-fast
67+
test-fast: ## Same as test except no coverage. ~1/4th the time depending on hardware.
68+
uv run pytest -n auto --dist=loadgroup
69+
6670
.PHONY: test-all-python
6771
test-all-python: ## Run tests on Python 3.9 to 3.13
6872
UV_PROJECT_ENVIRONMENT=.venv39 uv run --python 3.9 --all-extras --all-packages coverage run -p -m pytest

pydantic_ai_slim/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ dev = [
9696
"diff-cover>=9.2.0",
9797
"boto3-stubs[bedrock-runtime]",
9898
"strict-no-cover>=0.1.1",
99+
"pytest-xdist>=3.6.1",
99100
]
100101

101102
[tool.hatch.metadata]

tests/test_cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def test_agent_flag(
7575
assert cli(['--agent', 'test_module:custom_agent', 'hello']) == 0
7676

7777
# Verify the output contains the custom agent message
78-
assert 'using custom agent test_module:custom_agent' in capfd.readouterr().out
78+
assert 'using custom agent test_module:custom_agent' in capfd.readouterr().out.replace('\n', '')
7979

8080
# Verify ask_agent was called with our custom agent
8181
mock_ask.assert_called_once()
@@ -108,7 +108,7 @@ def test_agent_flag_set_model(
108108

109109
assert cli(['--agent', 'test_module:custom_agent', '--model', 'gpt-4o', 'hello']) == 0
110110

111-
assert 'using custom agent test_module:custom_agent with openai:gpt-4o' in capfd.readouterr().out
111+
assert 'using custom agent test_module:custom_agent with openai:gpt-4o' in capfd.readouterr().out.replace('\n', '')
112112

113113
assert isinstance(custom_agent.model, OpenAIModel)
114114

tests/test_examples.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ def reset_cwd():
8383
os.chdir(original_cwd)
8484

8585

86+
@pytest.mark.xdist_group(name='doc_tests')
8687
@pytest.mark.parametrize('example', find_filter_examples())
8788
def test_docs_examples( # noqa: C901
8889
example: CodeExample,

tests/test_messages.py

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import sys
2+
13
import pytest
24

35
from pydantic_ai.messages import AudioUrl, BinaryContent, DocumentUrl, ImageUrl, VideoUrl
@@ -135,29 +137,33 @@ def test_image_url_invalid():
135137
ImageUrl('foobar.potato').format
136138

137139

138-
@pytest.mark.parametrize(
139-
'document_url,media_type,format',
140-
[
141-
pytest.param(DocumentUrl('foobar.pdf'), 'application/pdf', 'pdf', id='pdf'),
142-
pytest.param(DocumentUrl('foobar.txt'), 'text/plain', 'txt', id='txt'),
143-
pytest.param(DocumentUrl('foobar.csv'), 'text/csv', 'csv', id='csv'),
144-
pytest.param(
145-
DocumentUrl('foobar.docx'),
146-
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
147-
'docx',
148-
id='docx',
149-
),
150-
pytest.param(
151-
DocumentUrl('foobar.xlsx'),
152-
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
153-
'xlsx',
154-
id='xlsx',
155-
),
156-
pytest.param(DocumentUrl('foobar.html'), 'text/html', 'html', id='html'),
157-
pytest.param(DocumentUrl('foobar.md'), 'text/markdown', 'md', id='md'),
158-
pytest.param(DocumentUrl('foobar.xls'), 'application/vnd.ms-excel', 'xls', id='xls'),
159-
],
160-
)
140+
_url_formats = [
141+
pytest.param(DocumentUrl('foobar.pdf'), 'application/pdf', 'pdf', id='pdf'),
142+
pytest.param(DocumentUrl('foobar.txt'), 'text/plain', 'txt', id='txt'),
143+
pytest.param(DocumentUrl('foobar.csv'), 'text/csv', 'csv', id='csv'),
144+
pytest.param(
145+
DocumentUrl('foobar.docx'),
146+
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
147+
'docx',
148+
id='docx',
149+
),
150+
pytest.param(
151+
DocumentUrl('foobar.xlsx'),
152+
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
153+
'xlsx',
154+
id='xlsx',
155+
),
156+
pytest.param(DocumentUrl('foobar.html'), 'text/html', 'html', id='html'),
157+
pytest.param(DocumentUrl('foobar.xls'), 'application/vnd.ms-excel', 'xls', id='xls'),
158+
]
159+
if sys.version_info > (3, 11): # pragma: no branch
160+
# This solves an issue with MIMEType on MacOS + python < 3.12. mimetypes.py added the text/markdown in 3.12, but on
161+
# versions of linux the knownfiles include text/markdown so it isn't an issue. The .md test is only consistent
162+
# independent of OS on > 3.11.
163+
_url_formats.append(pytest.param(DocumentUrl('foobar.md'), 'text/markdown', 'md', id='md'))
164+
165+
166+
@pytest.mark.parametrize('document_url,media_type,format', _url_formats)
161167
def test_document_url_formats(document_url: DocumentUrl, media_type: str, format: str):
162168
assert document_url.media_type == media_type
163169
assert document_url.format == format
@@ -232,6 +238,7 @@ def test_binary_content_is_methods():
232238
assert document_content.format == 'pdf'
233239

234240

241+
@pytest.mark.xdist_group(name='url_formats')
235242
@pytest.mark.parametrize(
236243
'video_url,media_type,format',
237244
[

uv.lock

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)