debuggingtestingand profiling purely with unit testing--testing individual functionsclassesand methodsto ensure that they behave according to our expectations key point of tddis that when we want to add feature--for examplea new method to class--we first write test for it and of course this test will fail since we haven' written the method now we write the methodand once it passes the test we can then rerun all the tests to make sure our addition hasn' had any unexpected side effects once all the tests run (including the one we added for the new feature)we can check in our codereasonably confident that it does what we expect--providing of course that our test was adequate for exampleif we want to write function that inserts string at particular index positionwe might start out using tdd like thisdef insert_at(stringpositioninsert)"""returns copy of string with insert inserted at the position string "abcderesult [for in range(- len(string )result append(insert_at(stringi"-")result[: ['abc-de''abcd- ''-abcde'' -bcde''ab-cde'result[ :['abc-de''abcd- ''abcde-''abcde-'""return string for functions or methods that don' return anything (they actually return none)we normally give them suite consisting of passand for those whose return value is used we either return constant (say or one of the argumentsunchanged--which is what we have done here (in more complex situations it may be more useful to return fake objects--third-party modules that provide "mockobjects are available for such cases when the doctest is run it will faillisting each of the strings ('abcd-ef''abcde- 'etc that it expectedand the strings it actually got (all of which are 'abcdef'once we are satisfied that the doctest is sufficient and correctwe can write the body of the functionwhich in this case is simply return string[:positioninsert string[position:(and if we wrote return string[:positioninsertand then copied and pasted string[:positionat the end to save ourselves some typingthe doctest will immediately reveal the error python' standard library provides two unit testing modulesdoctestwhich we have already briefly seen here and earlier (in and )and unittest in additionthere are third-party testing tools for