Label Integration Tests
Let’s learn about how to label integration tests with the pytest library.
We'll cover the following...
Before we move on to implementation, we always test the system to see if it will work with all of its components. To do this, we need to label the integration tests, exclude them by default, and create a way to run them. Since pytest supports labels, called marks, we can use this feature to add a global mark to an entire module.
Update the test cases
Let’s put the following code into the tests/repository/postgres/test_postgresrepo.py file.
import pytestpytestmark = pytest.mark.integrationdef test_dummy():pass
The module attribute pytestmark labels every test in the module with the integration tag. To verify that this works, we add a test_dummy test function, which always passes.
Update the pytest configuration
The marker needs to be registered in pytest.ini, as in the following code:
[pytest]minversion = 2.0norecursedirs = .git .tox requirements*python_files = test*.pymarkers = integration: integration tests
Perform the integration testing
We can now run pytest -svv -m integration to ask pytest to run only the tests ...