Chapter 21.1. Nose

Nose is a sophisticated and unobtrusive unit test framework for Python. It automatically discovers your tests (based on simple naming conventions), runs them, and reports the result. You can write simple test functions, unit test-based test cases or doctests. Nose will happily execute them all. Nose also knows how to intercept the standard Python assert, so you don’t need to learn and depend on some Nose-specific mechanism in your test code. Nose is not TurboGears-specific, and you can (and should) use it to test all your Python code. Let’s see Nose in action by testing a factorial function:

def factorial(n, recursive=True): """Computes the factorial of non-negative integers >>> factorial(0) 1 >>> factorial(5) 120 >>> factorial(4, ...

Get Rapid Web Applications with TurboGears: Using Python to Create Ajax-Powered Sites now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.