DEV Community

Discussion on: What components do you use to do TDD with Python?

Collapse
 
rhymes profile image
rhymes • Edited

I prefer pytest over unittest. The pros are:

  • you can write tests as functions (you can also use methods in classes like in unittest)
  • the conftest.py mechanism allows you to group setups that are evaluated only at necessity in a cascading fashion in sub folders
  • the test function explicitly declares what mocks it needs to run
  • fixtures make a great way to organize tests that need a complex setup and tests that can run super fast and have initializers that can be run per session, per test, per file/module
  • there are no custom assertion methods (you use mostly assert and with)
  • it's unittest compatible
  • it has lots of plugins

the cons are:

  • it requires a little bit of time to understand how fixtures work
  • it's one more package to install
Collapse
 
portfield10 profile image
portfield

Thank you for your very valuable opinion!
This is exactly what I was looking for.

The disadvantages seemed to be fine for me,
I would like to verify using pytest.

Collapse
 
tterb profile image
Brett Stevenson

I agree with everything here, except I actually found pytest fixtures to be pretty intuitive.