Python style guide
Testing
Overview
Testing at GitLab, including in Python codebases is a core priority rather than an afterthought. It is therefore important to consider test design quality alongside feature design from the start.
Use Pytest for Python testing.
Recommended reading
- Five Factor Testing: Why do we need tests?
- Principles of Automated Testing: Levels of testing. Prioritize tests. Cost of tests.
Testing levels
Before writing tests, understand the different testing levels and determine the appropriate level for your changes.
Learn more about the different testing levels, and how to decide at what level your changes should be tested.
Recommendation when mocking
- Use
unittest.mock
library. - Mock at the right level, for example, at method call boundaries.
- Mock external services and APIs.