Tests

Testing requirements

richard uses pytest-django to tie the Django test system to pytest.

We use FactoryBoy to generate model instances and test data.

Running tests

To run the tests, make sure your virtual environment is activated and then:

py.test tests/

You can see more options by doing:

py.test --help

Once you get a runline you like, put it in a bash script.

Add new tests

Conventions

Tests go in directories like tests/test_<APPNAME>/.

We use Factory Boy to generate model instances. Factory classes go in tests/test_<APPNAME>/factories.py.

Test modules should be named test_*.py.

Test classes should be named Test* and should extend Django’s UnitTest class.

Functions and methods should be named test_*.

Use the non-camel-case versions of assertXyz and friends if they exist.

See existing tests for examples.

We’re not shooting for 100% code coverage—only write tests that are compelling.

Make sure tests are documented and it’s clear what’s being tested and how.