O'Reilly logo

Python Testing Beginner's Guide by Daniel Arbuckle

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action - writing a more complex test

We'll write another test (you can add it to test.txt if you like) which shows off most of the details of doctest syntax.

  1. Insert the following text into your doctest file(test.txt), separated from the existing tests by at least one blank line:
    Now we're going to take some more of doctest's syntax for a spin.
    >>> import sys
    >>> def test_write():
    ... sys.stdout.write("Hello\n")
    ... return True
    >>> test_write()
    Hello
    True
    

    Think about it for a moment: What does this do? Do you expect the test to pass, or to fail?

  2. Run doctest on the test file, just as we discussed before. Because we added the new tests to the same file containing the tests from before, we still see the notification that three times three does ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required