Book Image

NumPy: Beginner's Guide

By : Ivan Idris
Book Image

NumPy: Beginner's Guide

By: Ivan Idris

Overview of this book

Table of Contents (21 chapters)
NumPy Beginner's Guide Third Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
NumPy Functions' References
Index

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 always fails:

    @knownfailureif(True)
    def test_alwaysfail():
         pass
  5. Define some test classes with methods that normally should be executed by nose:

    class TestClass():
       def test_true2(self):
          pass
    
    class TestClass2():
       def test_false2...