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.
- Install
nose
withsetuptools
:$ [sudo] easy_install nose
Or pip:
$ [sudo] pip install nose
- 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
- 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
- Define some
test
classes with methods that normally should be executed bynose
:class TestClass(): def test_true2(self): pass class TestClass2(...