When comparing pytest vs ward, the Slant community recommends pytest for most people. In the question“What are the best Python unit testing frameworks?” pytest is ranked 1st while ward is ranked 4th. 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. Pytest basically introduced the concept that Python tests should be plain Python functions instead of forcing developers to include their tests inside large test classes.
Ranked in these QuestionsQuestion Ranking
Pros
Pro Allows for compact test suites
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.
Pytest basically introduced the concept that Python tests should be plain Python functions instead of forcing developers to include their tests inside large test classes.
Pro Minimal boilerplate
Tests written with pytest need very little boilerplate code, which makes them easy to write and understand.
Pro Extensible (many of plugins are available)
Pytest can easily be extended with several hooks, and the same team develops a number of very useful plugins. For example, you install pytest-xdist, and parallel test execution just works, with all the same benefits you had with pytest (as opposed to having to use a separate test runner, for example)
Pro Fixtures are simple and easy to use
A fixture is just a function that returns a value and to use a fixture you just have to add an argument to your test function. You can also use a fixture from another fixture in the same manner, so it's easy to make them modular.
You can also parametrize fixture and every test that uses it will run with all values of parameters, no test rewrite needed. If your test uses several fixtures, all parameters' combinations will be covered.
Pro Very pretty and useful failure information
With most other tools you have to use debugger or extra logging to find out where did some value came from in your test. Not with pytest!
Pytest rewrites your test so that it can store all intermediate values that can lead to failing assert and provides you with very pretty explanation about what has been asserted and what have failed.
Pro Tests parametrization
You can parametrize any test and cover all uses of a unit without code duplication.
Pro Pdb just works
Pytest automagically (and safely) disables output capturing when you're entering pdb, so you don't have to redirect debugger to other console or bear huge amount of unneeded output from other tests.
Pro Provides special routines to make testing easier
Pytest provides developers with special routines to make test writing easier. This makes writing tests less error-prone and all around simple. It also results in shorter and more readable code.
Pro Test discovery by file-path
Pro Async fixtures
Fixtures can await asynchronous code.
Pro Explicit fixtures
Test fixtures are referenced explicitly, which helps both humans and IDE's understand which fixture is used.
Pro Encourages better test names
Tests are named by markdown strings, not the function name of the test.
Cons
Con Compatibility issues with other testing frameworks
The fact that pytest uses it's own special routines to write tests means that you are trading convenience for compatibility. In other words, writing tests for pytest means that you are tying yourself to only pytest and the only way to use another testing framework is to rewrite most of the code.
Con Not many plugins available (in 2022)
While ward has a plugin system, there are not many plugins available as of 2022. Alternatives, like pytest, have many more plugins to choose from.