You can control how nbmake treats specific notebooks by adding metadata to the .ipynb file. This is useful for overriding global settings for specific edge cases.
Execution Settings
Add an execution key to the notebook metadata to control timeouts and error tolerance:
{
"metadata": {
"execution": {
"timeout": 60,
"allow_errors": true
}
}
}
Cell-level Mocking and Post-Execution
You can use the nbmake metadata key within individual cells to inject state or run extra commands.
Mocking variables:
{
"metadata": {
"nbmake": {
"mock": {
"API_KEY": "fake_key",
"DEBUG_MODE": true
}
}
}
}
Note: String values are wrapped in quotes, while other types are passed as literals.
Post-cell execution:
{
"metadata": {
"nbmake": {
"post_cell_execute": [
"print('Cell finished!')",
"import os"
]
}
}
}
{
"metadata": {
"execution": {
"timeout": 60,
"allow_errors": true
},
"nbmake": {
"mock": {
"VAR": "val"
},
"post_cell_execute": ["print('done')"]
}
}
}