• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Shortcomings of Doc Tests

The most obvious problem with doc tests is that if you like to test attributes and properties, there is no doc string in which to place the tests. You can usually solve this problem by testing attributes implicitly in the context of other tests and/or place these tests in the class's doc string. This solution is good because attributes by themselves usually do not have much functionality, but they are used in combination with methods to provide functionality.

Next, it is not easy to test for certain outputs. The prime example here is None because it has no representation. The easy way around this issue is to make the testing statement a condition. So the statement methodReturningNone(), which should return None, is tested using methodReturningNone() is None, and the test should return True. There are also some issues when you're testing statements that return output whose representation is longer than a line because the doc string checker is not smart enough to remove the indentation whitespace. Good examples of such objects are lists and tuples. The best solution to this problem is to use the pretty printer module, pprint, which always represents objects in lines no longer than 80 characters and uses nice indentation rules for clarity.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint