Test actions¶
A test action has type: test and a test_type; all fields are flat on the
action. Test actions are skipped by default — they are validated and generated
only when lhp generate / lhp validate is run with --include-tests.
Each test action emits one temporary Lakeflow table (@dp.table(..., temporary=True))
whose query returns violation rows, with expectation decorators attached.
See also
How-to guides: Write a data test with a test action, Report test results to an external system.
Base fields¶
Common to every test action, regardless of test_type.
Field |
Type |
Required |
Default |
Description |
|---|---|---|---|---|
|
string |
Yes |
— |
Action name; unique within the flowgroup. |
|
string |
Yes |
— |
Must be |
|
string |
Yes |
— |
One of the nine types below. Any other value is rejected at validation. |
|
string |
No |
|
Name of the generated temporary table. |
|
string |
No |
|
Table comment and function docstring. |
|
string |
No |
|
|
|
string |
No |
— |
Correlates this test with a test-reporting hook. |
row_count¶
Compares record counts between exactly two sources within a tolerance.
Field |
Type |
Required |
Default |
Description |
|---|---|---|---|---|
|
list |
Yes |
— |
Exactly two tables/views whose counts are compared. |
|
integer |
No |
|
Allowed absolute difference in row counts. |
|
string |
No |
|
|
- name: orders_row_count
type: test
test_type: row_count
source: [v_orders_raw, v_orders_clean]
tolerance: 0
uniqueness¶
Asserts a unique constraint over one or more columns.
Field |
Type |
Required |
Default |
Description |
|---|---|---|---|---|
|
string |
Yes |
— |
Table or view to check. |
|
list |
Yes |
— |
Columns whose combined value must be unique. |
|
string |
No |
— |
WHERE-clause predicate restricting the rows checked. |
|
string |
No |
|
|
- name: orders_unique
type: test
test_type: uniqueness
source: v_orders_clean
columns: [order_id]
referential_integrity¶
Checks that source foreign-key values resolve in a reference table.
Field |
Type |
Required |
Default |
Description |
|---|---|---|---|---|
|
string |
Yes |
— |
Table or view holding the foreign-key values. |
|
string |
Yes |
— |
Three-part name ( |
|
list |
Yes |
— |
Foreign-key columns in |
|
list |
Yes |
— |
Key columns in |
|
string |
No |
|
|
- name: orders_customer_fk
type: test
test_type: referential_integrity
source: v_orders_clean
reference: main.sales.customers
source_columns: [customer_id]
reference_columns: [id]
completeness¶
Asserts that required columns are non-null.
Field |
Type |
Required |
Default |
Description |
|---|---|---|---|---|
|
string |
Yes |
— |
Table or view to check. |
|
list |
Yes |
— |
Columns that must be non-null. |
|
string |
No |
|
|
- name: orders_complete
type: test
test_type: completeness
source: v_orders_clean
required_columns: [order_id, customer_id, order_date]
range¶
Asserts a column’s values fall within min/max bounds.
Field |
Type |
Required |
Default |
Description |
|---|---|---|---|---|
|
string |
Yes |
— |
Table or view to check. |
|
string |
Yes |
— |
Column whose values are range-checked. |
|
number |
No |
— |
Inclusive lower bound. At least one of |
|
number |
No |
— |
Inclusive upper bound. At least one of |
|
string |
No |
|
|
- name: orders_amount_range
type: test
test_type: range
source: v_orders_clean
column: amount
min_value: 0
schema_match¶
Diffs two tables’ column schemas via information_schema.columns.
Field |
Type |
Required |
Default |
Description |
|---|---|---|---|---|
|
string |
Yes |
— |
Three-part name ( |
|
string |
Yes |
— |
Three-part name ( |
|
string |
No |
|
|
- name: orders_schema_match
type: test
test_type: schema_match
source: main.sales.orders
reference: main.sales.orders_expected
all_lookups_found¶
Asserts that every source row resolves against a lookup table.
Field |
Type |
Required |
Default |
Description |
|---|---|---|---|---|
|
string |
Yes |
— |
Table or view holding the lookup keys. |
|
string |
Yes |
— |
Three-part name ( |
|
list |
Yes |
— |
Key columns in |
|
list |
Yes |
— |
Matching columns in |
|
string |
No |
|
|
- name: orders_product_lookup
type: test
test_type: all_lookups_found
source: v_orders_clean
lookup_table: main.sales.products
lookup_columns: [product_id]
lookup_result_columns: [id]
custom_sql¶
Runs a SQL query whose returned rows are treated as violations.
Field |
Type |
Required |
Default |
Description |
|---|---|---|---|---|
|
string |
Yes |
— |
Query whose returned rows represent violations. |
|
string |
No |
— |
Table or view the query reads from. |
|
list |
No |
— |
Named expectations attached to the query; each carries its own |
- name: orders_negative_amount
type: test
test_type: custom_sql
source: v_orders_clean
sql: "SELECT * FROM v_orders_clean WHERE amount < 0"
expectations:
- name: no_negative_rows
expression: "amount >= 0"
on_violation: fail
custom_expectations¶
Attaches arbitrary named expectations to a source table/view.
Field |
Type |
Required |
Default |
Description |
|---|---|---|---|---|
|
string |
Yes |
— |
Table or view to attach expectations to. |
|
list |
Yes |
— |
List of expectation dicts; each carries its own |
- name: orders_custom_checks
type: test
test_type: custom_expectations
source: v_orders_clean
expectations:
- name: positive_amount
expression: "amount > 0"
on_violation: fail
Generated output¶
Every test action generates a function decorated with
@dp.table(name="<target>", comment="<description>", temporary=True) that
returns the violation query, plus one expectation decorator per violation
bucket. The on_violation value maps to the decorator as follows:
on_violation |
Decorator |
Behavior |
|---|---|---|
|
|
Pipeline update fails when any row violates. |
|
|
Violations recorded as metrics; rows retained. |
|
|
Violating rows dropped from the output. |
For the seven built-in types the action-level on_violation drives the
decorator. For custom_sql and custom_expectations the decorators are
built from each entry in expectations using that entry’s own
on_violation.