DocumentationTesting
Testing
A beginner's guide to testing in Pynions using pytest.
Testing with pytest
Quick Start
- Make sure you're in your virtual environment:
- Run all tests:
- Run tests with output:
Environment Setup
- Install test dependencies:
- Create basic test structure:
Basic Test Structure
Create test files in the tests/
directory:
Testing Async Functions
For testing async functions (like our Serper plugin):
Test Configuration
Create pytest.ini
in your project root:
Common Testing Patterns
1. Setup and Teardown
Use fixtures for common setup:
2. Testing Exceptions
3. Parametrized Tests
Running Specific Tests
Test Coverage
- Run tests with coverage:
- View coverage report:
Best Practices
-
Test File Organization
- Keep tests in
tests/
directory - Match source file structure
- Use clear test names
- Keep tests in
-
Test Naming
- Prefix test files with
test_
- Use descriptive test function names
- Example:
test_serper_search_returns_results
- Prefix test files with
-
Assertions
- Use specific assertions
- Test one thing per test
- Include error messages
-
Environment
- Use fixtures for setup
- Clean up after tests
- Don't modify production data
Debugging Tests
- Show print output:
- Enable debug logging:
- Use breakpoints:
Common Issues
-
Module Not Found
- Check virtual environment
- Install package in editable mode:
pip install -e .
-
Async Test Failures
- Use
@pytest.mark.asyncio
- Configure
asyncio_mode = auto
- Use
-
Fixture Errors
- Check fixture scope
- Verify fixture dependencies
Need help? Check the debugging guide: markdown:docs/debugging.md
Unit Tests
- Test successful responses
- Test error handling
- Test rate limiting
- Test invalid API keys
See the Serper plugin documentation for specific examples:
Updated 1 month ago
Edit this page