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.
Testing in Python vs. Ruby on Rails
Docs
Edit this page to fix an error or add an improvement in a merge request.
Create an issue to suggest an improvement to this page.
Product
Create an issue if there's something you don't like about this feature.
Propose functionality by submitting a feature request.
Feature availability and product trials
View pricing to see all GitLab tiers and features, or to upgrade.
Try GitLab for free with access to all features for 30 days.
Get help
If you didn't find what you were looking for, search the docs.
If you want help with something specific and could use community support, post on the GitLab forum.
For problems setting up or using this feature (depending on your GitLab subscription).
Request support