Skip to content

create_limetype_tables

Scope: function | Returns: callable

The create_limetype_tables fixture returns a callable that explicitly creates the database tables for the specified limetypes.

SQLite only

This fixture raises a RuntimeError when the test runs against SQL Server, because all tables are created upfront in that case and explicit creation is not needed.

Signature

create_limetype_tables(*lime_types: str | LimeType) -> None

Limetypes can be passed by name or as LimeType objects.

Background

With the default SQLite backend, tables are created lazily — a table is only created the first time its limetype is accessed through the limetype layer, for example by instantiating an object (lime_app.limetypes.company(...)) or running a query with lime_query. This is a deliberate performance trade-off: creating every table for every test would be slow for solutions with large schemas.

Code that goes through the limetype layer therefore never needs this fixture. create_limetype_tables exists for code that bypasses that layer.

When to use this fixture

If the code under test accesses tables directly — for example a repository class that runs raw SQL on a connection — lazy table creation is never triggered, and the query fails with "no such table". Use create_limetype_tables to ensure the tables are in place before such code runs:

import sqlalchemy


def test_repository_returns_empty_when_no_companies_exist(
    connection, create_limetype_tables
):
    create_limetype_tables("company")

    rows = connection.execute(sqlalchemy.text("SELECT * FROM company")).fetchall()

    assert rows == []