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 we will install nose
in case you don't have it yet.
Install
nose
withsetuptools
easy_install nose
Or
pip
:pip install nose
We will 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
We can 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
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
We will 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...