suppose we have written function def add(ab)return corresponding test function can then be def test_add(expected computed add( assert computed =expected' + =%gcomputed test functions can be in any program file or in separate filestypically with names starting with test you can also collect tests in subdirectoriesrunning py test - - will actually run all tests in all testpy files in all subdirectorieswhile nosetests - - restricts the attention to subdirectories whose names start with test or end with _test or _tests as long as we add integersthe equality test in the test_add function is appropriatebut if we try to call add( insteadwe will face the rounding error problems explained in sect and we must use test with tolerance insteaddef test_add(expected computed add( tol - diff abs(expected computedassert diff tol'diff=%gdiff below we shall write test functions for each of the three test procedures we suggestedcomparison with hand calculationschecking problems that can be exactly solvedand checking convergence rates we stick to testing the trapezoidal integration code and collect all test functions in one common file by the name test_trapezoidal py hand-computed numerical results our previous hand calculations for two trapezoids can be checked against the trapezoidal function inside test function (in file test_trapezoidal py)from trapezoidal import trapezoidal def test_trapezoidal_one_exact_result()"""compare one hand-computed result ""from math import exp lambda *( ** )*exp( ** computed trapezoidal( nexpected error abs(expected computedtol - success error tol msg 'error=% tol=% (errrortolassert successmsg