Test Database Builder for Python (TDBP)
Test Database Builder for Python (TDBP) is a lightweight framework that simplifies database integration testing by providing a fluent API for creating test database objects and test data.
It helps developers write cleaner, more maintainable database integration tests by eliminating boilerplate code and providing a consistent way to set up test data.
TDBP promotes the concept of disposable test setups. The compact code encourages keeping each test independent by having it create its own test dataset. This also makes reviews much easier, since setup execution and assertions are close to each other.
Please note that TDBP aims at functional tests, where the amount of data required for each test is usually small. If you need to test with large amounts of data, TDBP is not the right approach. It is especially ill-suited for performance testing.
This project is inspired by Exasol’s Test Database Builder for Java (https://github.com/exasol/test-db-builder-java).
Target Audience
TDBP is designed for:
Software developers writing database integration tests
QA engineers automating database tests
Database developers testing stored procedures and functions
Anyone needing to create temporary test database objects and data
Quick Start
We recommend to make the object factory a fixture in your integration test and purge the database before each test. This ensures test isolation.
The object factory needs a database connection. In case of the Exasol dialect, the pytest-exasol-backend (https://github.com/exasol/pytest-backend) makes creating an Exasol backend and getting a connection very convenient.
@pytest.fixture
def factory(connection):
factory = ExasolObjectFactory(connection)
factory.purge_user_objects() # Clean slate for each test
return factory
With that done, the test preparation gets very compact.
def test_insert_customers(factory):
# Prepare the test database
schema = factory.create_schema("SALES")
table = schema.create_table("CUSTOMERS",
ID="DECIMAL(12,0)", NAME="VARCHAR(255)")
table.insert(1, "Alice").insert(2, "Bob")
# Execute your test
# ...
# Assert the results
# ...
Information for Users
📖 User Guide: Detailed instructions on using TDBP including examples and best practices
Metadata
Release files for test-db-builder-python 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| test_db_builder_python-1.0.1.tar.gz | 7.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| test_db_builder_python-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.1 kB
Release files / test_db_builder_python-1.0.1.tar.gz
| Download URL | test_db_builder_python-1.0.1.tar.gz |
|---|---|
| Size | 7.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a6be788fa3ec16ac8f3e49e790b8d3705ddbf44a1c60724ca84b9cc35bf0f6d5
|
|
BLAKE2b-256 checksum How to use checksums |
8c41c51f15f4e7bdaab9ecd61f1ac1de630ed80282dd8d75ad1e2e2726d4aa3c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.3.0 CPython/3.12.13 Linux/6.17.0-1020-azure
|
Release files / test_db_builder_python-1.0.1-py3-none-any.whl
| Download URL | test_db_builder_python-1.0.1-py3-none-any.whl |
|---|---|
| Size | 10.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a162eb11ae6530e438d4a85622126c19a84aa8af80fa606da591dcff6b1b67f0
|
|
BLAKE2b-256 checksum How to use checksums |
5936d4b932d422b904b80c67094d43adde07a5d631971510c9891e09938648d2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.3.0 CPython/3.12.13 Linux/6.17.0-1020-azure
|