You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Feat: show only relevant columns (as DataFrames) when unit tests fail (#1741)
* Feat: show only relevant columns (as DataFrames) when unit tests fail
* Fix bug where astype would fail due to None being passed to non-nullable types
* Formatting
* Add flag to avoid truncating dataframe
* PR feedback
* Fix test
* Update docs
Copy file name to clipboardExpand all lines: docs/concepts/tests.md
+18-13Lines changed: 18 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -66,7 +66,9 @@ In this example, we'll use the `sqlmesh_example.full_model` model, which is prov
66
66
MODEL (
67
67
name sqlmesh_example.full_model,
68
68
kind FULL,
69
-
cron '@daily'
69
+
cron '@daily',
70
+
grain item_id,
71
+
audits [assert_positive_order_ids],
70
72
);
71
73
72
74
SELECT
@@ -75,14 +77,15 @@ SELECT
75
77
FROM
76
78
sqlmesh_example.incremental_model
77
79
GROUP BY item_id
80
+
ORDER BY item_id
78
81
```
79
82
80
83
Notice how the query of the model definition above references one upstream model: `sqlmesh_example.incremental_model`.
81
84
82
85
The test definition for this model may look like the following:
83
86
84
87
```yaml linenums="1"
85
-
test_full_model:
88
+
test_example_full_model:
86
89
model: sqlmesh_example.full_model
87
90
inputs:
88
91
sqlmesh_example.incremental_model:
@@ -110,7 +113,7 @@ Note that `ds` is redundant in the above test, since it is not referenced in `fu
110
113
Let's also assume that we are only interested in testing the `num_orders` output column, i.e. we only care about the `id` input column of `sqlmesh_example.incremental_model`. Then, we could rewrite the above test more compactly as follows:
111
114
112
115
```yaml linenums="1"
113
-
test_full_model:
116
+
test_example_full_model:
114
117
model: sqlmesh_example.full_model
115
118
inputs:
116
119
sqlmesh_example.incremental_model:
@@ -146,12 +149,13 @@ SELECT
146
149
FROM
147
150
filtered_orders_cte
148
151
GROUP BY item_id
152
+
ORDER BY item_id
149
153
```
150
154
151
155
Below is the example of a test that verifies individual rows returned by the `filtered_orders_cte` CTE before aggregation takes place:
152
156
153
157
```yaml linenums="1" hl_lines="16-22"
154
-
test_full_model:
158
+
test_example_full_model:
155
159
model: sqlmesh_example.full_model
156
160
inputs:
157
161
sqlmesh_example.incremental_model:
@@ -203,27 +207,28 @@ The command returns a non-zero exit code if there are any failures, and reports
Note: when there are many differing columns, the corresponding DataFrame will be truncated by default, but it can be fully rendered using the `-v` option (verbose) of the `sqlmesh test` command.
225
+
222
226
### Testing for specific models
227
+
223
228
To run a specific model test, pass in the suite file name followed by `::` and the name of the test:
224
229
225
230
```
226
-
sqlmesh test tests/test_suite.yaml::test_full_model
231
+
sqlmesh test tests/test_full_model.yaml::test_example_full_model
227
232
```
228
233
229
234
You can also run tests that match a pattern or substring using a glob pathname expansion syntax:
0 commit comments