The composability of fixtures in pytest is an improvement over traditional xUnit setup/teardown, reducing the incentive to commit testing crimes such as multi-stage and stepwise tests. This is great out of the box for unit tests, but I’m going to show how to combine the power of pytest fixtures with Docker to build high-level integration tests for microservices or other complex systems with multiple components. I’ll then build on that to show how to embed mock web services written with Flask right into the test code.

With a sample Java application that makes use of some external resources to offer a data processing service I’ll first quick an overview of Pytest, Docker, and Flask. Then I’ll mix some pre-built code with live test coding to demonstrate how to build high-level system tests which spin up the application and its dependencies in Docker. I’ll then mock one of the external dependencies using Flask, allowing the test to control and verify interaction between the system components. Finally I’ll show how to wrap the Flask application in a WSGI middleware that lets the test inspect interaction with the mocked service.

From a learning and development point of view, building your own is better than re-using someone else’s code so I’ll show how the support code for these features is relatively simple and how the audience can build it themselves to exactly meet their own needs. And I’ll do it all with a sense of fun, a joke or two and maybe a little storytelling.

#docker #python #flask #testing

System testing with Pytest, Docker, and Flask
30.85 GEEK