A Quick ‘nose’ tip
Why your unit tests might not be discovered by nose
Using nose for the first time
Out and about herding unit tests the other day I decided to try nose . nose is a unit test framework which provides test discovery and running facilities for python based unit tests. This seemed like what I needed given I had a lot of tests and I’d heard good things about nose.
Trying it Out
Everything went very well. I downloaded and installed – all very easy. Quickly scanned the usage doco and thought it was all good to go. The only problem was when I did
nose couldn’t find any of my tests. All very puzzling
A ‘gotcha’ I might save you from
Well I tried lots of stuff but the bottom line here is that I’d fallen prey to not being a regular expression parser … again ! The fact is that nose will, by default, look for files which match the regex
and what I hadn’t noticed was that isn’t going to find files like MyClassTest.py it will find, for instance, MyClass-Test.py but without that hyphen my precious tests were invisible ! Sadly (for me ) everyone of my tests was in a file named like MyClassTest.py !
More generally (and courtesy of a post on StackOverflow by Mark Rushakoff I came across) the following file patterns will match the nose default:
but as I discovered this will not
I discovered this whilst working on nose 0.11.3 under Python 2.6 .