Skip to main content

Home/ Mac Attack/ Group items tagged doctest

Rss Feed Group items tagged

Benjamin Bandt-Horn

25.2. doctest - Test interactive Python examples - Python v2.7.6 documentation - 0 views

  • common ways to use doctest: To check that a module’s docstrings are up-to-date by verifying that all interactive examples still work as documented. To perform regression testing by verifying that interactive examples from a test file or a test object work as expected. To write tutorial documentation for a package, liberally illustrated with input-output examples. Depending on whether the examples or the expository text are emphasized, this has the flavor of “literate testing” or “executable documentation”.
  • Running the module as a script causes the examples in the docstrings to get executed and verified
  • The file content is treated as if it were a single giant docstring; the file doesn’t need to contain a Python program! For example, perhaps example.txt contains this
  • ...8 more annotations...
  • You can instruct the Python interpreter to run the doctest module directly from the standard library and pass the file name(s) on the command line:
  • if M.__test__ exists and “is true”, it must be a dict, and each entry maps a (string) name to a function object, class object, or string
  • Which Docstrings Are Examined?
  • Any expected output must immediately follow the final '>>> ' or '... ' line containing the code, and the expected output (if any) extends to the next '>>> ' or all-whitespace line.
  • Execution Context?
  • Directives
  • Whitespace is not allowed between the + or - and the directive option name. The directive option name can be any of the option flag names explained above
  • Unittest
  •  
    Freaking Amazing.
1 - 1 of 1
Showing 20 items per page