napari / napari

napari: a fast, interactive, multi-dimensional image viewer for python
https://napari.org
BSD 3-Clause "New" or "Revised" License
2.13k stars 414 forks source link

Property-based testing for Napari #2444

Open Zac-HD opened 3 years ago

Zac-HD commented 3 years ago

Following some email discussions with @GenevieveBuckley, @sofroniewn, @tlambert03, @jni, and @fudgemunkey, I thought I'd write up our ideas for property-based testing of Napari as a public issue so that anyone can contribute ideas or pull requests. As background, Hypothesis is basically super-powered random testing, and I wrote this short paper on applying it to scientific code.

The best way to start is generally with a PR that adds Hypothesis to your CI - I prefer to make this a standard test dependency, though some projects have specific jobs for property-based tests instead - updates the test guide, and adds a single simple test. Then future PRs can focus on adding more tests and fixing any bugs that this reveals.

For Napari's first property-based tests, I'd use the following as a checklist (and try the ghostwriter):

[@sofroniewn suggests] focus on a small subset of the codebase first to make it tractable, rather than run on the whole thing. For example - the code inside napari/layers and testing our individual layer objects like napari.layers.Image, napari.layers.Points etc. These objects don't have any of our GUI/ Qt code in them and we definitely want them to be 100% rock solid across the range of their input types. (I'd ignore anything in a folder named venedored or experimental for now too).

tlambert03 commented 3 years ago

just wanted to say that I'm very excited about this :) Your paper was compelling and I'm wondering how I've made it this far without using property-based testing! (particular for widget inputs in magicgui... which would have revealed things like https://github.com/napari/magicgui/pull/178 far earlier). thanks again

GenevieveBuckley commented 3 years ago

I'm also excited to see what happens with this project!

sofroniewn commented 3 years ago

Thanks for the detailed write up @Zac-HD and the enthusiasm from the community. I know @neuromusic and @goanpeca were also interested in this too!

The best way to start is generally with a PR that adds Hypothesis to your CI - I prefer to make this a standard test dependency, though some projects have specific jobs for property-based tests instead - updates the test guide, and adds a single simple test.

I think this is a reasonable place to start, it will make it very clear what we're taking on by adding hypothesis support. If we decide to remove hypothesis in the future for whatever reason we can use that PR as a reference too, and it should be easy to revert.

My understanding from a quick look at the hypothesis docs is that it will integrate with our current pytest framework and so these tests can run alongside our current ones for each of the environment / OS configurations in our current grid, which would be nice.

If you'd like to start with such a PR, we'd be happy to review.

Then future PRs can focus on adding more tests and fixing any bugs that this reveals.

Yes sounds good! I like those categories you propose above. I'd be happy to weigh in with more advice on where to start as we get to this point.

I'm looking forward to the first PR! :-)

brisvag commented 3 years ago

This sounds super cool! I'm going to play around with hypothesis elsewhere too :) I think starting with layers would be great, it would help with at least 4 of the issues I raised (#1801, #1833, #2347, #2348) ;)