Loading Databricks updates...
← All video guides
Data and AI Platform

Python Unit Testing in Databricks with AI Error Diagnosis

Discover, run, and debug Python unit tests in Databricks without switching tools.

In short

Discover, run, and debug Python unit tests in Databricks without switching tools. Use the testing sidebar, inline execution icons, AI-powered error diagnosis, and a dedicated results pane to iterate faster.

Source: Databricks announcement

Key takeaways

  • Databricks notebooks support pytest-style unit testing with testing sidebar and execution icons.
  • AI error diagnosis analyzes test failures and automatically suggests fixes.
  • Test discovery recognizes pytest conventions: test_*.py files and functions starting with 'test'.
  • Results pane displays test status, failure details, and AI-generated error suggestions.

Chapters

  • 0:00 — Introduction
  • 0:35 — Test File Conventions (pytest naming rules)
  • 0:54 — Running Tests in the Databricks UI (sidebar, execution, results)
  • 1:37 — Understanding Test Failures (results pane, failure details)
  • 2:05 — Fixing & Re-running Tests (error diagnosis, code fix, selective re-run)
  • 2:43 — Databricks Ecosystem Overview (outro/branding)

Frequently asked questions

How do I write tests in Databricks?

Use pytest conventions: name files test_*.py or *_test.py, and create functions/methods starting with 'test'.

Can I run tests directly in notebooks?

Yes. The testing sidebar, inline execution icons, and results pane enable seamless testing without switching tools.

How does AI error diagnosis help?

AI analyzes test failures and suggests fixes automatically, reducing debugging time significantly.

Full transcript

Auto-generated from the video and lightly edited for readability. Timestamps link to the moment in the video.

Show full transcript (8 segments)

0:04Hi folks, I have good news for you. Datab bricks makes it simple to discover, run and track Python unit test right inside the workspace. You can now test through like the testing sidebar, inline execution icons and result pane or without switching tools. These features work only of course when you open a valid Python test file. Database

0:26recognize files named using py test conventions such as test underscore python file or underscore test python file. It identifies test based on names that start with test either as a standalone functions or as a method inside class that starts with test. These classes should not have an init method and they can include static or

0:50class methods marked with the proper decorator. Let's switch to the UI to show you how you can get started. You can see that I have inside this folder two scripts. The uh pricing.py that contains the function and then we have the test pricing which contains of course the test and automatically Databricks detects that this is the testing file.

1:12You can see that I have a new icon over here called test. And what I can do I can either run old unit test pricing or I can run class by class. So what I can do I'm going to of course click on run all tests and after few seconds I will see which function passed the test and which function did fail and as you can

1:34see the first one did pass successfully the second one as well and then let's let's see the third one. So it says that um $50 should qualify while it's not the case over here. So I can either click on diagnose the uh the error to see how the assistant will be able to help me. So

1:58basically it says that the amount should be higher than or equal to 50. So let's fix this. The amount has been yeah subtotal sorry. Okay. So it should be equal and then let's run it. Now that everything is good, let's go the uh the

2:21I have the option to run everything or run only the failed test. So let's run only the failed test and see whether it's going to be successful or not. Here we go. And you see the test was successful. And now it's very easy to do all your tests inside database without giving the UI. Thank you. See you soon.

2:43Dreams [music] the flow iceberg and delta lake tables a glow. Unity catalog governs lake base strong [music] genuin [music] scale higher and higher next drop it.

Official Databricks resources

Related

Databricks Answers

Looking for a quick, source-backed answer? Browse Databricks Answers on the Databricks Data and AI Platform — direct, documentation-validated answers to common Databricks questions, curated by Youssef Mrini, Senior Developer Advocate at Databricks.