4 ms·
And in python you can use doctests (tests inside de docstrings of functions)
by mdew 5y ago
And in python you can use doctests (tests inside de docstrings of functions)
- bialpio 5y agoThat's also pretty nice, although elevating those tests to be first-class-citizens makes more sense to me. My approach is that "code is truth, despite what the comment says", and docstrings feel too much like comments, but I haven't used Python professionally that much so I just may not be used to those.
- piperswe 5y agoI haven't used doctests in Python, but I have in Rust. It really helps that any code blocks in a docstring is a doctest by default, so they ensure that examples in your documentation stay evergreen. It's nice to know that if there's a code example in documentation, it will compile and run properly and hasn't been broken.
- Waterluvian 5y agoPractically speaking how useful are the Rust doctests? I thought they looked like a genius idea but I don’t get how they work 95% of the time when examples don’t come with all the plumbing required to make valid state for a function to actually work on.
- justinpombrio 5y agoThere's a feature for that: you prefix the plumbing with `#`, and it runs in the doctest but doesn't render on the doc page. https://doc.rust-lang.org/rustdoc/documentation-tests.html#hiding-portions-of-the-example https://doc.rust-lang.org/rustdoc/documentation-tests.html#h...
- Waterluvian 5y agoThat would help. I’ll have to experiment to better understand if it all works well enough. I’m thinking about Python unittest having setUp function for preparing every test without repeating myself. Maybe Rust has a similar way to define setup code for every test.
- adsharma 5y agoI'm looking to do something in this general area better than doctests. Looking for collaborators. http://adsharma.github.io/pysmt http://adsharma.github.io/pysmt