Skip to main content

Write compact code to setup up database contents in integration tests

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

test_db_builder_python-1.0.0.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

test_db_builder_python-1.0.0-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file test_db_builder_python-1.0.0.tar.gz.

File metadata

  • Download URL: test_db_builder_python-1.0.0.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.12.12 Linux/6.14.0-1017-azure

File hashes

Hashes for test_db_builder_python-1.0.0.tar.gz
Algorithm Hash digest
SHA256 9ca5bf81e01afedf45e1c4300f8a2864b1208daef0fd5c07b076cc2d0524c588
MD5 98dd1149062aef4c8bb01bf2a26fb97b
BLAKE2b-256 9d3b2030e89edc4b1b84af65205a8b04516bb88c23ab0564d0b9b23114603e50

See more details on using hashes here.

File details

Details for the file test_db_builder_python-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for test_db_builder_python-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 334b99b8df188d42ae372e37de86bb1be6a1dfed5637297b8db7c3287029f138
MD5 9c33c96e4c166535b93f4b8fd99ab625
BLAKE2b-256 2bd535e1ea1081a4e4c4d725edc8fa85797f6673fcbf307e7ffa0c4beca8907d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page