What is a trade-off of keeping functions and tests inside notebooks rather than in Python modules?
- Exam domain
- MLOps44% of the exam
- Difficulty
- Medium
- In this mock
- 22 questions on this domainPractise this domain
Why the exam asks this
Objective in the exam guide: Compare the benefits and challenges of approaches for organizing functions and unit tests.
Organizing functions and unit tests is named.
Why B is the answer
Notebooks are quick to start, but modules are easier to reuse, review and test in CI
Inline notebook code is fast for exploration. Modules in repo files can be imported, reviewed as plain code and tested with standard tools.
Remember: Modules for reusable, tested code.
How it works
Code layout affects testability.
In detail
- Notebooks: quick.
- Modules: reusable and testable.
Every option, checked
Knowing why each wrong option fails is how you rule it out on exam day.
A. Modules cannot be imported by notebooksWrong
Notebooks import workspace files.
B. Notebooks are quick to start, but modules are easier to reuse, review and test in CIRight
Modules for reusable, tested code.
C. There is no differenceWrong
Testability differs.
D. Notebooks are always better because tests in modules cannot run on Databricks clusters at allWrongMost tempting
Module tests run on clusters and in CI.
Why it tempts: Notebook-first habits run deep.
Use case
An illustrative scenario, not a real incident.
Illustrative: shared feature code moves to a src/ package tested in CI.
See it in different ways
flowchart TD
Q{"Will they be reused and tested?"}
Q -->|"Yes"| A0["Python modules"]
Q -->|"One-off exploration"| A1["Notebook"]How to read this chart
- At "Will they be reused and tested?": if "Yes", go to "Python modules"; if "One-off exploration", go to "Notebook".
mindmap
root(("Code layout"))
n1["Notebooks"]
n2["Fast"]
n3["Hard to test"]
n4["Modules"]
n5["Reusable"]
n6["CI friendly"]How to read this chart
- The centre is "Code layout".
- "Notebooks" covers "Fast", "Hard to test".
- "Modules" covers "Reusable", "CI friendly".