#51: Parametrised Tests With Pytest
Parametrised tests are a great help to create many test cases without the need to write many tests. Let us look how they work in pytest.
Parametrised tests are a great help to create many test cases without the need to write many tests. Let us look how they work in pytest.
The bigger our test suite gets, the longer it takes to run all tests. With markers we get a nice way to tell pytest which test it should run and which not.
While built-in fixtures are a great help, they cannot address the specific needs of our applications. It is now time to have a closer look on how to create our own fixtures.
Yield is a funny little keyword that allows us to create functions that return one value at a time. Let us look how yield works and how we can use it to create a generator.
Fixtures are a powerful feature in pytest. You can write your own fixtures as a replacement for setup and teardown methods or use the built-in ones to access common functionality. This post has a closer look to the fixtures that come directly with pytest and shows you how to use them.
I prefer code that throws an exception as soon as it detects an unrecoverable situation. This is annoying but a lot less troublesome as when those errors go unnoticed to production. How can we test if our code throws the expected exceptions?
While trying to get a better understanding of pytest fixtures, I noticed a little problem: I could not see the output of the print() statements in my code. Let’s look why this happens and how we can change it.
Flask is a great framework, but before I continue with more elaborate parts I need to make sure that the code I wrote until now keeps working. Let’s look how we can test our code in Python.
Sooner or later our Flask application will be on the internet. The earlier we address security issues the better it is. Today we look at a first simple measure to add security headers.
View functions are the main part of a Flask application. If we keep adding them to the same file, we quickly will be unable to maintain our application. Luckily for us, Flask comes with a solution to that problem called Blueprint.