While we haven't done any testing yet, we can assure you that you won't just be writing one test. Nope. You'll be writing lots of tests. Fortunately, nose has a nice little test discovery feature that comes in handy.
In our previous example, we have two test files, 'unittest_toy.py' and 'test_toy.py.' Nose has this great test discovery feature that basically says, prefix your test files and functions with 'test' and nose will find and execute them. So let's add another test to the mix called 'test_more_stuff.py':
def test_this(): assert True def test_that(): assert 2 > 1 def test_the_other_thing(): assert "f" in "foo"
Now let's run 'test_more_stuff.py' with nose:
[terryp@tpmacbook] code :: nosetests test_more_stuff.py ... ---------------------------------------------------------------------- Ran 3 tests in 0.001s OK
Great, we're still going! Okay, how about now we actually try out this discovery business. Let's just let nose find our tests!
[terryp@tpmacbook] code :: nosetests .... ---------------------------------------------------------------------- Ran 4 tests in 0.005s OK
It found four tests this time, but which four? Add a little verbosity into the mix by passing in the '-v' option:
[terryp@tpmacbook] code :: nosetests -v test_more_stuff.test_this ... ok test_more_stuff.test_that ... ok test_more_stuff.test_the_other_thing ... ok test_toy.test_toy ... ok ---------------------------------------------------------------------- Ran 4 tests in 0.005s OK
See how it found test_more_stuff.py and test_toy.py? Pretty cool.
As mentioned in the previous section, nose has a few caveats you should keep in mind when trying to write compatible tests:
Fluid 960 Grid System, created by Stephen Bau, based on the 960 Grid System by Nathan Smith. Released under the GPL/ MIT Licenses.