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
About the Author
About the Reviewers
NumPy Functions' References

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:

    def test_false():
    def test_true():
  3. Skip tests with the @skipif decorator. Let's use a condition that always leads to a test being skipped:

    def test_skip():
  4. Add a test function that always passes. Then, decorate it with the @knownfailureif decorator so that the test always fails:

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

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