Time for action – decorating tests

We will apply the @setastest decorator directly to test functions. Then we will apply the same decorator to a method to disable it. Also, we will skip one of the tests and fail another. First, install nose in case you don't have it yet.

  1. Install nose with setuptools:
    $ [sudo] easy_install nose
    

    Or pip:

    $ [sudo] pip install nose
    
  2. Apply one function as being a test and another as not being a test:
    @setastest(False)
    def test_false():
       pass
    
    @setastest(True)
    def test_true():
       pass
  3. Skip tests with the @skipif decorator. Let's use a condition that always leads to a test being skipped:
    @skipif(True)
    def test_skip():
       pass
  4. Add a test function that always passes. Then, decorate it with the @knownfailureif decorator so that the test ...

Get NumPy : Beginner's Guide - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.