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 - normalizing whitespace

We'll write a couple tests that demonstrate how whitespace normalization works.

  1. Insert the following text into your doctest file:
    Next, a demonstration of whitespace normalization.
    >>> [1, 2, 3, 4, 5, 6, 7, 8, 9]
    ... # doctest: +NORMALIZE_WHITESPACE
    [1, 2, 3,
    4, 5, 6,
    7, 8, 9]
    >>> sys.stdout.write("This text\n contains weird spacing.")
    ... # doctest: +NORMALIZE_WHITESPACE
    This text contains weird spacing.
    
  2. Run the tests using doctest and the following screen is displayed:
    Time for action - normalizing whitespace
  3. Notice how one of the tests inserts extra whitespace in the expected output, while the other one ignores extra whitespace in the actual output. ...

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