Pytest and coverage Tool
Run py.test tool
Exit after failing X tests
Use this to Profile your tests (time taken)
coverage within the project
Add this to show which lines were not covered
Packages to install:
pip install pytest
pip install pytest-sugar
pip install pytest-cov
Coverage Configuration File
exclude_lines = the lines as they are in Python code
Pytest with Flask
client = app.test_client()
Gives you an
Test Client object
Makes a GET request
Makes a POST request
Makes a PUT request
You can create a test client to test your Flask app
Scope for the fixture: Can be
For each value, the fixture will be called with that value (this makes multiple calls)
All tests in the session use the fixture automatically
request object in fixture gives you access to the
pytest request (e.g. put a
See all available fixtures
The purpose of test fixtures is to provide a fixed baseline upon which tests can reliably and repeatedly execute.
In short, mocking is creating objects that simulate the behaviour of real objects.
Help Us Go Positive!
We offset our carbon usage with Ecologi. Click the link below to help us!