Writing tests with pytest!

So, we now have pytest as a test runner, but what about using it to write tests too?

I’ve seen the sentiments presented here that perhaps we don’t want to couple too closely to pytest, however that was now over 5 years ago and in that time pytest has grown to be well established and the often preferred test framework due to it’s simplicity.

Even python core devs prefer pytest!

Also, maybe Guido himself

Transitions are easy since pytest supports both unittest and pytest (duh) tests. Anyways, are opinions still the same, or is it time to make testing a bit easier?

Quick anecdote: When I first got into testing with python, I also had to make the choice between using unittest and pytest. I tried both, and found pytest immensely more intuitive, so I stuck with that. Even today, I still find myself referring back to the unittest docs about how to do certain things and which assert* call I need to make.

So, perhaps pytest can also ease the barrier for new guys trying to write tests.

I have no particular objection! I don’t mind using unittest directly personally, but if folks like pytest I don’t see any real downsides. It seems pretty convenient.

1 Like