Testing sample code in python modules

Posted by Andrew Walker on Stack Overflow See other posts from Stack Overflow or by Andrew Walker
Published on 2010-05-07T13:38:01Z Indexed on 2010/05/07 16:28 UTC
Read the original article Hit count: 485

Filed under:
|
|

I'm in the process of writing a python module that includes some samples. These samples aren't unit-tests, and they are too long and complex to be doctests. I'm interested in best practices for automatically checking that these samples run.

My current project layout is pretty standard, except that there is an extra top level makefile that has build, install, unittest, coverage and profile targets, that delegate responsibility to setup.py and nose as required.

projectname/
    Makefile
    README
    setup.py
    samples/
        foo-sample
        foobar-sample
    projectname/
        __init__.py
        foo.py
        bar.py
    tests/
        test-foo.py
        test-bar.py

I've considered adding a sampletest module, or adding nose.tools.istest decorators to the entry-point functions of the samples, but for a small number of samples, these solutions sound a bit ugly.

This question is similar to http://stackoverflow.com/questions/301365/automatically-unit-test-example-code, but I assume python best practices will differ from C#

© Stack Overflow or respective owner

Related posts about testing

Related posts about python