Tooling
We make use of the following tools when writing unit tests:
- Python's unittest library
- nose (deprecated) — Add-ons for Python unit testing
- This handles running our test suites, providing enhanced testing capabilities and plugins for code coverage, easier test running, and more.
- This is only used for older versions of our products (see Running Python Unit Tests)
- pytest — Modern test runner for Python unit tests
- kgb — A library for spying on function calls and overriding behavior
- We generally favor this over tools like mock, as it allows us to continue working with real-world objects, overriding only small parts at a time (like the result of an HTTP request).
- Django's test infrastructure
Test Cases
Our main code bases (Djblets and Review Board) have their own base TestCase
class that all test suites must inherit from. These provide additional assertion methods, object construction, and testing functionality that will be useful to your tests.
Djblets
When writing a new test suite for Djblets, your class will inherit from djblets.testing.testcases.TestCase
(documentation). This is based on Django's own django.test.testcases.TestCase
, offering utilities for:
- Overriding siteconfig settings (used for dynamic Django settings and custom settings for applications)
- Additional assertion methods
- Optimized Django fixture loading (automatically speeds up most unit tests behind-the-scenes)