lime_types¶
Scope: session | Returns: list[LimeType]
The lime_types fixture defines the set of LimeType objects that describe your test database schema. Other fixtures such as database and lime_app depend on it.
Default implementation¶
By default, lime_types returns limetypes that closely match the structure of the lime-core database. Replace it in your conftest.py to test against your own schema — which is what most projects do.
Basic usage¶
Most tests don't use lime_types directly. Define it in your conftest.py to establish the schema for your test suite:
import pytest
import lime_type
@pytest.fixture(scope="session")
def lime_types():
return lime_type.create_limetypes_from_dsl({
"company": {
"name": {"type": "string", "required": True, "length": 200},
"status": {
"type": "option",
"options": ["prospect", "active", "excustomer"],
"defaultvalue": "prospect",
},
},
"person": {
"firstname": {"type": "string", "required": True, "length": 32},
"lastname": {"type": "string", "length": 50},
"company": {
"type": "belongsto",
"related": "company",
"backref": "person",
},
},
})
Keep the session scope
Always use scope="session" on your lime_types fixture. Changing it to a narrower scope is possible but requires careful consideration of how dependent fixtures behave.
Multiple definitions in different modules¶
You can define lime_types in multiple conftest.py files at different levels of your test tree. pytest resolves the nearest definition, so sub-directories can use a different schema from the one at the top level:
tests/
conftest.py # defines lime_types with company and person
billing/
conftest.py # overrides lime_types with subscription and invoice types
test_invoicing.py # uses the billing schema
crm/
test_contacts.py # uses the top-level schema
This is useful when different parts of your test suite exercise different database structures and don't need to carry the full schema everywhere.
Defining the schema in a YAML file¶
create_limetypes_from_dsl accepts both a dict and a YAML string: