Preparing testing scenarios
Tests are typically prepared in batches. Similar tests require a similar setup and cleanup, and they only differ on small details. Repeating the same preparation over and over generates boilerplate code and it's less readable.
The term boilerplate comes from 19th century local newspapers printing already-prepared news stamped onto metal plates by distribution companies. This meant the same news, in the same format, was repeated all across different newspapers. Boilerplate code is reused code that presents little or no variation, and, in most cases, mainly adds clutter. When creating tests, it is easy to fall into this pattern, which makes the code cumbersome.
In this recipe, we will see how to prepare setup scenarios to run tests using pytest
fixtures.
Getting ready
We will use the pytest
module. We should install the modules, adding them to our requirements.txt
file as follows:
$ echo "pytest==5.4.1" >...