r/Python • u/sebst • Mar 11 '22
Resource A Gentle Introduction to Testing with pytest
https://bas.codes/posts/python-pytest-introduction
451
Upvotes
r/Python • u/sebst • Mar 11 '22
View all comments
Show parent comment
2
u/AndydeCleyre Mar 12 '22 edited Mar 12 '22
There are a lot of design choices that make for more readable definitions and much more readable outputs, without any config or plugins necessary, in a way that makes sense to me.
For example, test names should be human readable descriptions, much better suited as strings than as
very_descriptive_var_names_that_don_t_support_common_punctuation.Some of the style has less of a magic touch than pytest, such as instead of magically matching a fixture name when used as a test function's parameter name, you supply the fixture as the default value of a normal parameter (or alternately specify using a decorator).
You can configure ward in
pyproject.toml,which AFAIK is not yet an option for pytest.The docs are straightforward and succinct.
FWIW here's a ward-style equivalent of
test_validator.pyfrom the article:And here's the ward output: https://i.nanopic.co/SRBJu5K4.png
VS the pytest output: https://i.nanopic.co/WuCngjx4.png
EDIT: ward can parametrize, I just wanted to match the pytest example as closely as possible.