Skip to content

Pytest vs Unittest

BraveJero edited this page Oct 4, 2021 · 5 revisions

When comparing unittest vs pytest, the community recommends pytest for most people. The most important reason people chose pytest is:

The idioms that pytest first introduced brought a change in the Python community because they made it possible for test suites to be written in a very compact style, or at least far more compact than was ever possible before.Slant community

Pytest

Pros

  • Allows for compact test suites
  • Fixtures are simple and easy to use
  • Minimal boilerplate
  • Very pretty and useful failure information
  • Tests parametrization
  • Extensible (many of plugins are available)
  • Pdb jus works
  • Provides special routines to make testing easier
  • Test discovery by file-path

Cons

  • Compatibility issues with other testing frameworks

Unittest

Pros

  • Part of the Python standard library
  • Flexible test case execution
  • Promotes grouping related tests into common test suites
  • Very fast test collection
  • Easy to use for people who are comfortable with testing in other languages
  • Very precise test duration reports

Cons

  • camelCase naming
  • No color output
  • Verbose

References

Clone this wiki locally