Help on writing unit tests for MoinMoin

Why write tests?

In short, writing tests is easy, fun and make others feel good about your code. Some developers of MoinMoin feel that no code should be accepted without working tests.

Read more on: UnitTest

Running the tests

Run the tests each time you change the code. If your code broke the tests - fix it before you commit or send a patch.

You can run all the tests from the command line:

# run from moin root directory
py.test

If you just want to run some specific test:

cd MoinMoin/_tests
py.test test_sourcecode.py  # just runs the sourcecode test

How MoinMoin tests work

MoinMoin._tests package (and other _tests packages living below other packages) contain all the unit tests.

The tests use py.test at least version 0.9.1, with some MoinMoin specific magic that will help you to write tests in no time.

Anatomy of a MoinMoin _tests package

(!) IMPORTANT: a test module name MUST start with "test_" to be included in the tests.

Anatomy of MoinMoin test module

See MoinMoin/_tests/_test_template.py.

Why do some tests fail? Why are some tests skipped?

Skipping tests

Use py.test.skip("The reason why this test is skipped.") to skip a test.

Test coverage

To find out how good your test coverage is, you first need to ensure that each test module has a top-level global coverage_modules listing the tested modules. For example, MoinMoin/_tests/test_Page.py contains

coverage_modules = ['MoinMoin.Page']

Then you'll need to install the coverage module.

Finally, run your tests with py.test -C to get a coverage report at the end. Note that this greatly slows down the tests.

See MoinMoin/conftest.py for (slightly) more information.

Links

MoinMoin: MoinDev/UnitTests (last edited 2008-11-03 21:18:17 by GregWard)