Let Hypothesis Break Your Python Code Before Your Users Do
towardsdatascience.com·1d
Flag this post

, you should take testing your code seriously. You might write unit tests with pytest, mock dependencies, and strive for high code coverage. If you’re like me, though, you might have a nagging question lingering at the back of your mind after you finish coding a test suite.

“Have I thought of all the edge cases?”

You might test your inputs with positive numbers, negative numbers, zero, and empty strings. But what about weird Unicode characters? Or floating-point numbers that are NaN or infinity? What about a list of lists of empty strings or complex nested JSON? The space of possible inputs is huge, and it’s hard to think of the myriad different ways your code could break, especially if you’re under some time pressure.

Property-based testing flips that burden from you to the …

Similar Posts

Loading similar posts...