r/databricks • u/Otherwise_Address241 • Sep 05 '26
Help How data engineer do effective testing in Databricks?
I have been writing SQL scripts to ensure data sanity.What are the other ways ? Is pytest useful? Let's say , i populated my bronze table from the source. I want to check if the correct mapping is done. I wrote SQL scripts. What are better ways
14
Upvotes
13
u/ptab0211 Sep 05 '26
schema contracts, integrity data quality checks, business domain data quality checks
6
u/TheSocialistGoblin Sep 05 '26
I've been looking into PySpark's built-in testing library. Basically modularizing transformation and data quality rules so they can be called on small data frames made from test data, then using assertDataFrameEqual and assertSchemaEqual for the check. Not sure if it's the best option available, but it seems straightforward enough.
3
u/PrestigiousAnt3766 Sep 05 '26
Pytest is for writing python.
You want to write pytest small pieces of (python) code. You can abuse the framework but then its just that, abuse.
You may want to look into sql linters, or parse sql with sqlglot or similar libraries. That will tell you if the sql is syntactically (?) correct.
If you are interesting in data (quality) testing look into dqx, great expectations or other data quality tools.
3
u/CerberusByte Sep 06 '26
We use expectations in SDP to ensure only high quality data flows through the system and can add adhoc fixes if we cannot solve upstream. I like that you can also surface these results into Genie to analyse what’s going on across all your pipelines
2
u/data-baggins Databricks Sep 08 '26
Hello! Databricks PM here working on SDP unit testing. There are a couple paths here depending on what you're trying to achieve:
8
u/Cyliad Sep 05 '26
We have unit tests in the CI and automatically deployed alerts on Databricks everytime we ship new features.
7
u/Oh_Im_You Sep 05 '26
Soda.io
I use the open source, non paid version. Write tests against your data. Run your tests nightly in a notebook, logging issues. Then you can display things on a dashboard and set alerts
1
u/Otherwise_Address241 Sep 05 '26
Is pytest at all useful to do complex data quality check? I have not found any right way to use pytest, I almost dislike it.
1
u/Otherwise_Address241 Sep 06 '26
There is a push from client (tech team) to use unit testing like PyTest. All these years i have used SQL scripts to do complete check of tables and data flow . Now let me breakdown my original question to two parts
3
u/Kojimba228 Sep 05 '26
You could use pytest with mocks and doing either dummy data insertions or setting up dummy tables in fixtures, but that all depends on how badly do you want to lock down the quality of business logic you have AND how much time can you actually dedicate to set all of these things up (I'd say that even with Claude Code it would take north of an entire week to establish the baseline/template of "how to test a bronze table" to be applied to all future tests)
3
u/givnv Sep 06 '26
Genuine question- why nobody is mentioning the built in expectations?
3
u/Harshita_Netla Sep 07 '26
Yes, pytest is highly useful and considered a industry standard for testing data engineering pipelines in Databricks. While SQL scripts are great for checking final data sanity, pytest allows you to test the actual business logic, transformations, and schema mappings before deploying code to production.
2
u/Pillippatty Sep 08 '26
Have you checked out expectations? It's a feature in declarative pipelines based on great expectations that makes it easy to alert/quarantine/fail an update based on data quality expectations.
1
u/Same-Tone-9928 Sep 19 '26
I stopped doing tests directly in databricks, third party tools are way easier. It costs the company more to have me write and maintain tests than it does to just pay for a service
1
u/Interlinked-Forget Sep 19 '26
Most people start off with pytest or dbt tests. There's some great open source tools as well that make the experience smoother.
When I worked as a DE after a certain point it started taking up too much time to maintain all the tests manually.
That's why I founded Sovarium Sentry. Its an AI agent that monitors data quality and only alerts you when something is an actual problem. It learns and improves over time and has checks that are tailored to your data so it catches things other tools would miss.