Take the 2-minute tour ×  I'm using nose for testing. I know how
to skip test, but I was wondering if there's an easy solution to
write a decorator to skip tests, when some module is not
imported.  Right now I try to import mock and catch the
ImportError if it isn't installed and set mock = None. At the
start of tests that require mock I use if not mock: raise
SkipTest() as the 1st line.  That works alright. I'm just
wondering if it's also possible with a decorator. I've tried to
write one for some time... after figuring out the thing with
__name__ I thought i got it. But then I noticed, that all my
test using that decorator pass no matter what.   I've been using
Using kindall's answer for some time, just to notice today, that
it still doesn't work right (at least not in all cases)!  It
seems to work, when I use a test function, that is not a
generator (contains no yield statement). Whenever I use the
decorator on a test function that uses yield, the test passes no
whatter what assert fails in the yielded fun