Pytest-mock and unittest mock

328 Views Asked by At

I'm new to Python and recently, I've seen that since Python 3.3, if I'm not mistaken, unittest is the standard testing framework.

I'm working on a project that uses Pytest with the pytest-mock plugin. Reading the plugin documentation, I saw that it is a thin wrapper of unittest mock, and the patch API is the same. So my question is, why to use pytest-mock plugin instead of avoid adding one more dependency to your project and just go with unittest mock?

I tried reading the documentation for both, unittest and pytest / pytest-mock, but I can't seem to find arguments that would justify using pytest-mock if I could just use the standard unittest.

1

There are 1 best solutions below

0
On

This is answered here, but personally I would use pytest-mock plugin, it's better in

  1. Making the code look cleaner
  2. More readable
  3. Is more powerful
  4. Easier to test targets with no return values And so on.