# Is nbval a viable candidate for testing our example Jupyter notebooks?

**URL:** <https://www.rubin.community/t/is-nbval-a-viable-candidate-for-testing-our-example-jupyter-notebooks/1585>\
**Category:** Data Management\
**Tags:** ci, doc-engineering, jupyter, tutorials\
**Created:** [January 25, 2017, 3:32pm UTC](https://www.rubin.community/t/is-nbval-a-viable-candidate-for-testing-our-example-jupyter-notebooks/1585 "2017-01-25T15:32:23Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mwv](https://avatars.discourse-cdn.com/v4/letter/m/e79b87/32.png) [@mwv](https://www.rubin.community/u/mwv)\
**Post date:** [January 25, 2017, 3:32pm UTC](https://www.rubin.community/t/is-nbval-a-viable-candidate-for-testing-our-example-jupyter-notebooks/1585/1 "2017-01-25T15:32:24Z")

</div>

Testing of example code in Jupyter notebooks will be helpful in ensuring that our tutorials and related examples remain current. Does anyone have any experience with `nbval`, which is supposed to integrate with the py.test framework?

> **[computationalmodelling/nbval](https://github.com/computationalmodelling/nbval)**
>
> A py.test plugin to validate Jupyter notebooks. Contribute to computationalmodelling/nbval development by creating an account on GitHub.

Are there other similar packages that are worth investigating?

---

<div class="post-metadata">

**Author:** ![jsick](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/jsick/32/672_2.png) [@jsick](https://www.rubin.community/u/jsick)\
**Post date:** [January 25, 2017, 3:55pm UTC](https://www.rubin.community/t/is-nbval-a-viable-candidate-for-testing-our-example-jupyter-notebooks/1585/2 "2017-01-25T15:55:28Z")

</div>

Thanks @mwv, I need to try it out still but I imagine that’s what we’ll want for documentation testing. 👍

_Mini-update_: it seems to do the testing by comparing computed output against saved output cells. I’ll have to see if this can do everything for us, or if there’s an addition need for ‘hidden’ test cells that contain py.test test functions.

I also noticed [nblint](https://github.com/alexandercbooth/nblint) recently for flake8-ing notebook code, and then there’s [nbdime](https://github.com/jupyter/nbdime) for diffing notebooks. This looks like a good technology stack for CI’ing our docs.

---

<div class="post-metadata">

**Author:** ![swinbank](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/swinbank/32/24_2.png) [@swinbank](https://www.rubin.community/u/swinbank)\
**Post date:** [January 25, 2017, 3:59pm UTC](https://www.rubin.community/t/is-nbval-a-viable-candidate-for-testing-our-example-jupyter-notebooks/1585/3 "2017-01-25T15:59:40Z")

</div>

I have no experience of nbval, so I can’t answer the question directly.

However, I wonder if we should actually take a step back and ask what our preferred mechanism for presenting tutorials and examples actually is (or, rather, will be). I’d prefer us to take a unified, coherent approach to this, rather than attempting to expand our systems (and our readers’ patience) to cover whatever formats we can think of.

For example, given the approach pipelines documentation described in [DMTN-030](https://dmtn-030.lsst.io), I’d imagine one could construct a good argument that we’d should embed tutorials directly in the documentation, written as reStructuredText documents and [tested appropriately](http://www.sphinx-doc.org/en/1.5.2/ext/doctest.html), rather than by trying to graft on notebooks (which, arguably, will never integrate properly with Sphinx).

I don’t take an opinion on which route we should go down for now, but I do think we should step back and think about how we actually want our tutorials to work before we focus on the details of the technology.

---

<div class="post-metadata">

**Author:** ![timj](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/timj/32/10_2.png) [@timj](https://www.rubin.community/u/timj)\
**Post date:** [January 25, 2017, 4:00pm UTC](https://www.rubin.community/t/is-nbval-a-viable-candidate-for-testing-our-example-jupyter-notebooks/1585/4 "2017-01-25T16:00:51Z")

</div>

Slight tangent here, but is the plan to replace all our current `examples/` code with tested code? I get the impression that most of our examples will only work by fluke.

---

<div class="post-metadata">

**Author:** ![jsick](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/jsick/32/672_2.png) [@jsick](https://www.rubin.community/u/jsick)\
**Post date:** [January 25, 2017, 4:02pm UTC](https://www.rubin.community/t/is-nbval-a-viable-candidate-for-testing-our-example-jupyter-notebooks/1585/5 "2017-01-25T16:02:17Z")

</div>

> [@swinbank](#):
>
> I don’t take an opinion on which route we should go down for now, but I do think we should step back and think about how we actually want our tutorials to work before we focus on the details of the technology.

I’ve got some ideas about a workflow where examples are written natively in Sphinx, but can be output into notebooks for users to try at home or on the Science Platform. You’re absolutely right that I should write up a proposal for this.

---

<div class="post-metadata">

**Author:** ![swinbank](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/swinbank/32/24_2.png) [@swinbank](https://www.rubin.community/u/swinbank)\
**Post date:** [January 25, 2017, 4:03pm UTC](https://www.rubin.community/t/is-nbval-a-viable-candidate-for-testing-our-example-jupyter-notebooks/1585/6 "2017-01-25T16:03:37Z")

</div>

My opinion is that untested examples are actually worse than useless: they are actively instructing folks to do things which won’t work. From that point of view, I strongly think that _ought_ to be the plan.

In terms of resource allocation, it rather depends how our current work prototyping the ideas set forth in DMTN-030 proceeds, together with if & how we converge in discussions like this one, and the availability of person-power to actually do the work.

---

<div class="post-metadata">

**Author:** ![jsick](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/jsick/32/672_2.png) [@jsick](https://www.rubin.community/u/jsick)\
**Post date:** [January 25, 2017, 4:04pm UTC](https://www.rubin.community/t/is-nbval-a-viable-candidate-for-testing-our-example-jupyter-notebooks/1585/7 "2017-01-25T16:04:06Z")

</div>

> [@timj](#):
>
> Slight tangent here, but is the plan to replace all our current examples/ code with tested code? I get the impression that most of our examples will only work by fluke.

Yes, it’d also be worth having a discussion about this. I think we should _eventually_ deprecate `examples/` in their current form and only have examples that are driven by documentation and tested as part of documentation CI. So whether there’s anything in `examples/` or not is an implementation detail.

---

<div class="post-metadata">

**Author:** ![KSK](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/ksk/32/393_2.png) [@KSK](https://www.rubin.community/u/KSK)\
**Post date:** [January 25, 2017, 4:42pm UTC](https://www.rubin.community/t/is-nbval-a-viable-candidate-for-testing-our-example-jupyter-notebooks/1585/8 "2017-01-25T16:42:43Z")

</div>

> [@swinbank](#):
>
> My opinion is that untested examples are actually worse than useless: they are actively instructing folks to do things which won’t work. From that point of view, I strongly think that ought to be the plan.

I agree strongly with this. I don’t have a notion of how much work it would take, but (at least for the python examples) it would be useful to go through and convert the ones that can be `doctest`ed in rST and pitch the rest of them.

---

<div class="post-metadata">

**Author:** ![timj](https://sea2.discourse-cdn.com/flex002/user_avatar/www.rubin.community/timj/32/10_2.png) [@timj](https://www.rubin.community/u/timj)\
**Post date:** [January 25, 2017, 4:44pm UTC](https://www.rubin.community/t/is-nbval-a-viable-candidate-for-testing-our-example-jupyter-notebooks/1585/9 "2017-01-25T16:44:54Z")

</div>

> [@KSK](#):
>
> at least for the python examples

This might be an interesting JTM hack session: collaboratively migrating a few examples into a testable form.
