Time for action - creating and running your first doctest
We'll create a simple doctest, to demonstrate the fundamentals of using doctest.
- Open a new text file in your editor, and name it
- Insert the following text into the file:
This is a simple doctest that checks some of Python's arithmetic
>>> 2 + 2
>>> 3 * 3
- We can now run the doctest. The details of how we do that depend on which version of Python we're using. At the command prompt, change to the directory where you saved
- If you are using Python 2.6 or higher, type:
$ python ‑m doctest test.txt
- If you are using python 2.5 or lower, the above command may seem to work, but it won't produce the expected result. This is because Python 2.6 is the first version ...