Our aim is that all new functionality is adequately tested.
We use py.test for unit testing. You need at least py.test >= 1.0.0
To run the all tests in the current directory and its subdirectories.
py.test
to run tests in a specific test file.
py.test storage/test_dtd.py
We use some of the py.test plugins for simplify testing
The recwarn plugin allows us to test for Warnings.
recwarn is a funcargs plugins which means that you need it in your test function parameters.
def test_example(recwarn): # do something w = recwarn.pop() # w.{message,category,filename,lineno} assert 'something' in str(w.message)
To test for DeprecationWarning it is even simpler:
from py.test import deprecated_call def test_something(): deprecated_call(function_to_run, arguments_for_function)
Will check that a function that we run raises a DeprecationWarning
The xfail decorator is part of the skipping plugin. xfail allows us to run tests that we expect to fail.
This allows you to do the following:
The simplest form is the following:
@py.test.mark.xfail def test_function(): ...
You can also pass the following parameters:
Run tests with Pootle 2.x this way:
./manage.py test pootle_store pootle_app
Some of the other Django applications also have tests, but don't run in our default setup, so it is probably best to ignore them for now. If you use Django 1.2, the tests should run out of the box, as long as you don't use database cache but rather in-memory cache or memcached. With older versions of Django, disable the page following middleware in pootle/settings.py: