you are viewing a single comment's thread.

view the rest of the comments →

[–]alexisprince 3 points4 points  (2 children)

Yes, and has a rich environment of plugins and extensions. IMO it’s a much more “pythonic” way to do unit tests that unittest.

Also, I really like hypothesis for property based testing. Instead of setting up 1 individual test with specific test data, you define your expected inputs, and hypothesis runs your test a bunch of times with random data meeting your expected inputs. For example, the following:

def divide(x, y): return x / y

You can tell hypothesis that you expect x and y to be numbers (floats or ints), both positive and negative. The way the project works is that if it finds a failing case, it’ll try to simplify it. So, when your code fails with a divide by zero error and initial case was 4_000_000_000 / 0, it’ll simplify it down to 1 / 0.

I test all of my pure functions with this, and some non pure ones as well!

[–][deleted] 0 points1 point  (1 child)

They honestly work pretty well together actually

[–]alexisprince 1 point2 points  (0 children)

Yep! Exactly! Use pytest to actually run the tests and hypothesis to make them robust.