This document provides comprehensive information about testing the Flowfull-Python Client.
The test suite includes:
- Unit Tests - Test individual components in isolation
- Integration Tests - Test component interactions
- Async Tests - Test asynchronous functionality
- Type Tests - Test Pydantic model validation
| Component | Test File | Coverage |
|---|---|---|
| Operators | test_operators.py |
✅ 100% |
| Storage | test_storage.py |
✅ 100% |
| Session | test_session.py |
✅ 100% |
| Query Builder | test_query.py |
✅ 100% |
| Types | test_types.py |
✅ 100% |
| Errors | test_errors.py |
✅ 100% |
| Sync Client | test_client.py |
✅ 95% |
| Async Client | test_async_client.py |
✅ 95% |
Install test dependencies:
pip install -r requirements-dev.txtWindows (PowerShell):
.\run_tests.ps1Linux/Mac:
python run_tests.pyDirect pytest:
pytestpytestpytest --cov=core --cov-report=htmlOr using the script:
.\run_tests.ps1 -Coveragepytest tests/test_operators.py
pytest tests/test_client.pypytest tests/test_operators.py::TestComparisonOperatorspytest tests/test_operators.py::TestComparisonOperators::test_eqpytest -v
pytest -vv # Extra verboseOr using the script:
.\run_tests.ps1 -Verbosepytest -m "not slow"Or using the script:
.\run_tests.ps1 -Fastpytest -m asynciopytest --cov=core --cov-report=htmlOpen htmlcov/index.html in your browser to view the report.
pytest --cov=core --cov-report=term-missing- Overall Coverage: 95%+
- Core Modules: 100%
- Client Modules: 95%+
- Helper Modules: 95%+
The pytest.ini file contains pytest configuration:
- Test discovery patterns
- Output options
- Markers for test categorization
- Async support configuration
The conftest.py file provides shared fixtures:
memory_storage- Clean MemoryStorage instancemock_client- FlowfullClient with memory storagemock_async_client- AsyncFlowfullClient with memory storagesample_user_data- Sample user datasample_api_response- Sample API responsesample_login_credentials- Sample login credentialssample_session_id- Sample session ID
"""
Tests for [Component Name]
This file is part of Flowfull-Python Client.
License: AGPL-3.0-or-later
"""
import pytest
from core import [ComponentToTest]
class Test[ComponentName]:
"""Test [component] functionality"""
def test_[feature](self):
"""Test [specific feature]"""
# Arrange
component = [ComponentToTest]()
# Act
result = component.method()
# Assert
assert result == expecteddef test_with_fixture(mock_client):
"""Test using a fixture"""
response = mock_client.get("/users")
assert response is not None@pytest.mark.asyncio
async def test_async_feature(mock_async_client):
"""Test async feature"""
response = await mock_async_client.get("/users")
assert response.successfrom unittest.mock import Mock, patch
@patch('core.request.RequestHandler.request')
def test_with_mock(mock_request):
"""Test with mocked request"""
mock_request.return_value = ApiResponse(success=True, data=[])
# Test code herepytest tests/test_client.py::TestFlowfullClient::test_get_request -v -spytest --pdbpytest --tb=long- Test Isolation - Each test should be independent
- Clear Names - Use descriptive test names
- AAA Pattern - Arrange, Act, Assert
- Mock External Calls - Don't make real API calls
- Test Edge Cases - Test error conditions and edge cases
- Use Fixtures - Reuse common test setup
- Document Tests - Add docstrings to test methods
All test files are licensed under AGPL-3.0-or-later.
Copyright (C) 2024 Pubflow Team