Skip to content

Commit 36ca65a

Browse files
doc (#76)
1 parent cc939ba commit 36ca65a

File tree

1 file changed

+46
-4
lines changed

1 file changed

+46
-4
lines changed

README.md

+46-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717

1818
## Quick Start
1919

20-
```
20+
If you have a notebook that runs interactively using an ipython kernel,
21+
you can try testing it automatically as follows:
22+
23+
```sh
2124
pip install pytest nbmake
2225
pytest --nbmake **/*ipynb
2326
```
@@ -105,8 +108,10 @@ If you are using another language such as c++ in your notebooks, you may have a
105108

106109
## Parallelisation
107110

108-
Parallelisation with xdist is experimental upon initial release, but you can try it out:
109-
```
111+
For repos containing a large number of notebooks that run slowly, you can run each notebook
112+
in parallel using `pytest-xdist`.
113+
114+
```sh
110115
pip install pytest-xdist
111116

112117
pytest --nbmake -n=auto
@@ -118,11 +123,48 @@ It is also possible to parallelise at a CI-level using strategies, see [example]
118123

119124
Using xdist and the `--overwrite` flag let you build a large jupyter book repo faster:
120125

121-
```
126+
```sh
122127
pytest --nbmake --overwrite -n=auto examples
123128
jb build examples
124129
```
125130

131+
## Mock out variables to simplify testing (experimental 🧪)
132+
133+
If your notebook runs a training process that takes a long time to run, you can use nbmake's
134+
mocking feature to overwrite variables after a cell runs:
135+
136+
```json
137+
{
138+
"cells": [
139+
...,
140+
{
141+
"cell_type": "code",
142+
"execution_count": null,
143+
"metadata": {
144+
"nbmake": {
145+
"mock": {
146+
// these keys will override global variables after this cell runs
147+
"epochs": 2,
148+
"config": "/test/config.json",
149+
"args": {
150+
"env": "test"
151+
}
152+
}
153+
}
154+
},
155+
"outputs": [],
156+
"source": [
157+
"epochs = 10\n",
158+
"..."
159+
]
160+
},
161+
...
162+
],
163+
...
164+
}
165+
```
166+
167+
126168
## Advice on Usage
127169

128170
nbmake is best used in a scenario where you use the ipynb files only for development. Consumption of notebooks is primarily done via a docs site, built through jupyter book, nbsphinx, or some other means. If using one of these tools, you are able to write assertion code in cells which will be [hidden from readers](https://jupyterbook.org/interactive/hiding.html).

0 commit comments

Comments
 (0)