This directory contains the complete test suite for the rhosocial-activerecord core package. Tests use the Provider Pattern, supporting unified testing across multiple backends and Python versions.
tests/
├── conftest.py # pytest root configuration, sets testsuite environment
├── providers/ # Test provider implementations (Provider Pattern)
│ ├── basic.py # Basic functionality test provider
│ ├── events.py # Event system test provider
│ ├── mixins.py # Mixin class test provider
│ ├── query.py # Query functionality test provider
│ ├── registry.py # Provider registry
│ └── scenarios.py # Scenario test provider
└── rhosocial/activerecord_test/
├── feature/ # Feature tests
│ ├── backend/ # Backend-related tests
│ ├── basic/ # Basic functionality tests
│ ├── events/ # Event system tests
│ ├── interface/ # Interface tests
│ ├── mixins/ # Mixin class tests
│ ├── query/ # Query functionality tests
│ └── relation/ # Relationship tests
└── realworld/ # Real-world scenario tests (reserved)
The Provider pattern is the core mechanism for achieving backend-agnostic testing. Each Provider encapsulates test data preparation and cleanup logic for specific functionality, enabling test suite reuse across backends.
| File | Responsibility |
|---|---|
basic.py |
Basic CRUD, field mapping, type adapter tests |
events.py |
Lifecycle events, event handler tests |
mixins.py |
Optimistic lock, soft delete, timestamp mixin tests |
query.py |
Query builder, aggregation, JOIN, CTE tests |
registry.py |
Global Provider registry for testsuite lookup |
scenarios.py |
Complex business scenario tests |
Workflow:
conftest.pysets theTESTSUITE_PROVIDER_REGISTRYenvironment variable- Testsuite finds corresponding Provider implementations via the registry
- Providers are responsible for creating test models, preparing data, and cleaning up resources
Backend-related tests are organized by functionality module and backend type:
| Subdirectory | Content |
|---|---|
base/ |
Base backend protocol, transaction management, hook function tests |
dialect/ |
SQL dialect protocol tests (CTE, window functions, arrays, JSON, etc.) |
dummy/ |
Dummy backend basic functionality tests (no real database connection) |
dummy2/ |
Dummy backend advanced functionality tests (window functions, advanced mixins) |
sqlite/ |
SQLite backend core functionality tests |
sqlite2/ |
SQLite batch operation tests (batch DML/DQL, transactions) |
sqlite3/ |
SQLite column mapping and RETURNING clause tests |
sqlite4/ |
SQLite introspection tests (table, column, index info queries) |
sqlite_async/ |
Async backend functionality tests |
sqlite_pragma_extension/ |
SQLite PRAGMA extension functionality tests |
Directory Numbering Explanation:
- Unnumbered directories (e.g.,
sqlite/): Core functionality tests - Numbered directories (e.g.,
sqlite2/,sqlite3/): Specialized functionality tests, numbered by development order
Tests for ActiveRecord core functionality:
test_crud.py- Create, Read, Update, Delete operationstest_fields.py- Field definition and typestest_validation.py- Data validationtest_field_column_mapping.py- Field to column mappingtest_type_adapter.py- Type adapterstest_basic_mapped_models.py- Basic mapped models
Tests for model lifecycle events:
test_lifecycle.py- Lifecycle hooks (before_save, after_save, etc.)test_handlers.py- Event handler registration and execution
Tests for reusable mixin classes:
test_optimistic_lock.py- Optimistic locking mechanismtest_soft_delete.py- Soft delete functionalitytest_timestamps.py- Automatic timestampstest_combined_articles.py- Combined mixin tests
Tests for query builder functionality:
test_active_query_basic.py- Basic queriestest_active_query_join.py- JOIN operationstest_active_query_aggregate.py- Aggregate functionstest_active_query_range.py- Range queriestest_active_query_set_operation.py- Set operations (UNION, etc.)test_aggregate_queries.py- Aggregate queries
Tests for model relationships:
test_base.py- Basic relationshipstest_interfaces.py- Relationship interfacestest_async_descriptors.py- Async descriptorstest_batch_*.py- Batch loading tests
Reserved directory for real business scenario integration tests. These tests simulate complex business logic combinations to validate ActiveRecord behavior in real applications.
# Activate virtual environment in project root
source .venv3.14/bin/activate
# Run all tests
pytest tests/# Run feature tests only
pytest tests/rhosocial/activerecord_test/feature/
# Run backend tests only
pytest tests/rhosocial/activerecord_test/feature/backend/
# Run SQLite introspection tests only
pytest tests/rhosocial/activerecord_test/feature/backend/sqlite4/pytest tests/rhosocial/activerecord_test/feature/basic/test_crud.py# Run tests with specific markers
pytest -m "not slow" tests/- Test files start with
test_ - conftest.py for pytest fixtures
- schema/ subdirectories for test SQL schema files
- Test classes start with
Test - Use descriptive names, e.g.,
TestSQLiteBackendTransaction
- Test methods start with
test_ - Use underscores to separate words, describe test scenario
- Example:
test_insert_with_returning_clause
- Use standard fixtures provided by testsuite
- Use
select_fixture()utility to select version-appropriate fixtures - Python 3.8 uses base models, 3.10+ uses enhanced models
rhosocial-activerecord-testsuite is an independent test suite package that defines test interfaces and common test logic. This project implements the interfaces defined in testsuite through the Provider pattern, enabling tests to run across backends.
testsuite (defines interfaces) ← providers/ (implements interfaces) ← feature/ (concrete tests)
- Create a new directory under
feature/backend/(e.g.,mysql/) - Create
conftest.pyto configure fixtures - Write test files
- Add corresponding Provider implementation in
providers/
- Determine which feature module the test belongs to
- Create test file in the corresponding directory
- If new fixtures are needed, update
conftest.pyorproviders/
- Create a new Provider file under
providers/ - Inherit from the base interface defined in testsuite
- Implement all required methods
- Register in
registry.py
Problem: Schema files not found when running tests
Solution: Ensure schema files are in the correct feature directory and verify the Provider's _load_sqlite_schema method points to the correct directory.
Problem: Cannot import ActiveRecord or other modules
Solution: Ensure the library is installed in development mode (pip install -e .) or PYTHONPATH includes the src directory.
Problem: Test suite cannot find provider implementations
Solution: Check that providers are correctly registered in providers/registry.py and that interface names match those defined in testsuite.
Problem: Tests not running with expected database configurations
Solution: Verify scenario definitions in providers/scenarios.py and ensure the provider correctly returns available scenarios.
Problem: Tests complaining about fixture parameters
Solution: Ensure bridge files correctly import fixtures from testsuite and tests in testsuite receive fixtures as parameters.
- Tests in the testsuite package define testing contracts but don't import fixtures directly
- Bridge files in this repository import fixtures from testsuite and make them available to pytest
- Providers handle database setup and model configuration for each test
- Schema files are centralized by feature to maintain organization
- The architecture allows the same tests to run against different backends