integ-tests/python/README.md
⚠️ IMPORTANT NOTE
This document was initially generated by an AI assistant and should be taken with a grain of salt. While it provides a good starting point, some information might be inaccurate or outdated. We encourage contributors to manually update this document and remove this note once the content has been verified and corrected by the team.
If you find any inaccuracies or have improvements to suggest, please feel free to submit a PR updating this guide.
This directory contains integration tests for the BAML Python client. These tests verify the functionality of the Python client library and ensure it works correctly with various BAML features.
uv installeduv sync
# Note: env -u CONDA_PREFIX is needed if you're using Conda to avoid conflicts
uv run maturin develop --uv --manifest-path ../../engine/language_client_python/Cargo.toml
uv run baml-cli generate --from ../baml_src
infisical run --env=test -- uv run pytest
# Run tests in a specific file
infisical run --env=test -- uv run pytest tests/test_functions.py
# Run a specific test
infisical run --env=test -- uv run pytest tests/test_functions.py -k "test_name"
infisical (default)infisical run --env=test -- uv run pytest
uv run pytest
For CI environments, use:
infisical run --env=test -- uv run pytest --no-cov
# Run all commands from the root of the repo
$ docker build -t baml-python-test -f integ-tests/python/docker-tests/test-package.Dockerfile .
# cargo build often fails with out of memory errors, so we need to increase the memory limit
$ docker run --memory=8g --volume ./:/app -it baml-python-test /bin/sh
$ cd integ-tests/python
# Build the python client
$ uv run maturin develop --manifest-path ../../engine/language_client_python/Cargo.toml
$ uv run pytest
tests/ - Test filesbaml_client/ - Generated BAML client codeapp/ - Example application codedocker-tests/ - Docker-based integration testspyproject.toml - Python project configurationuv.lock - Locked dependenciesInstall the Python Test Explorer extension for VS Code
Create a launch configuration in .vscode/launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Tests",
"type": "python",
"request": "launch",
"runtimeExecutable": "infisical",
"runtimeArgs": [
"run",
"--env=test",
"--"
],
"program": "${workspaceFolder}/.venv/bin/pytest",
"args": [
"-v",
"-s"
],
"console": "integratedTerminal",
"justMyCode": false
}
]
}
print() statements in your tests-s flag to show print statements:infisical run --env=test -- uv run pytest -s
BAML_LOG=trace for detailed BAML client logs:BAML_LOG=trace infisical run --env=test -- uv run pytest
Missing API Keys
.env file exists if not using Infisicalinfisical runBuild Issues
# Clean and rebuild
rm -rf target/
uv run maturin develop --uv --manifest-path ../../engine/language_client_python/Cargo.toml
uv sync
Test Timeouts
@pytest.mark.timeout(60)
def test_long_running():
...
BAML Client Generation Issues
../baml_src are validrm -rf baml_client
uv run baml-cli generate --from ../baml_src
Conda Environment Conflicts
env -u CONDA_PREFIX when running maturin commandsinfisical run --env=test -- uv run pytest -v
infisical run --env=test -- uv run pytest -s
First, add your test definitions in the BAML source files (see BAML Source README):
baml_src/clients.bamlbaml_src/test-files/providers/uv run baml-cli generate --from ../baml_src
This will create new Python client code in baml_client/.
Create a new test file in tests/ directory:
import pytest
from baml_client.functions import TestAnthropicCompletion
class TestAnthropic:
@pytest.mark.asyncio
async def test_basic_completion(self):
result = await TestAnthropicCompletion(
input="What is the capital of France?"
)
assert result == "Paris"
@pytest.mark.asyncio
async def test_error_handling(self):
with pytest.raises(Exception):
await TestAnthropicCompletion(
input="Test input"
)
# Run all tests
infisical run --env=test -- uv run pytest
# Run specific test file
infisical run --env=test -- uv run pytest tests/test_anthropic.py
# Run specific test
infisical run --env=test -- uv run pytest tests/test_anthropic.py -k "test_basic_completion"
test_ prefixtests/ directoryTest Setup
baml_client@pytest.mark.asyncio for async testsAssertions
@pytest.mark.timeout(30)
@pytest.mark.asyncio
async def test_long_running():
...
Environment