Nose Hates Me

I easy_install’d nose on my iMac some time in the last month, and tried to use it with options for the first time today, and I’ve found that a good number of the ones shown in ‘nosetests –help’ are actually not recognized when I run nosetests. Meanwhile, running nosetests with no options still works fine. This is 0.11.3 on OS X. Google gives me only references to plugins not being found. These are allegedly “built in”! Nobody replied on Twitter either, which is pretty odd in my experience. So here I am. Wtf is going on here?

For sure, -x and -v aren’t recognized, and -p *is* recognized. Using ‘-w’ with ‘.’ as an argument results in ‘no option -w’, but feeding it a non-existent directory results in a Python ValueError (/foo not found, or not a directory). Wtf?

In checking out /Library/Python/2.6/site-packages/nose-0.11.3-py2.6.egg/nose/config.py, I can see that these options are defined, so I’m a bit confused. Here’s a small sampling of output:

Brian-Joness-iMac:tests bjones$ nosetests -x 
Usage: nosetests [options]

nosetests: error: no such option: -x
Brian-Joness-iMac:tests bjones$ nosetests -v 
Usage: nosetests [options]

nosetests: error: no such option: -v
Brian-Joness-iMac:tests bjones$ nosetests 
..
----------------------------------------------------------------------
Ran 2 tests in 0.360s

OK

Clues hereby solicited.

  • http://www.doughellmann.com/ Doug Hellmann

    You might get some help on the TiP mailing list (http://lists.idyll.org/listinfo/testing-in-python).

    The first thing that comes to my mind is to check whether the nosetests executable you’re running is the one that is looking at the modules in the site-packages directory you reference above. Could you have more than one copy of nosetests installed (via a virtualenv or a package manager like Homebrew)?

  • ajung

    I think you are using optparse somewhere? I was running into a similar issue with some script involved using the optparse module on the module level…

  • m0j0

    @ajung — do you recall the fix? After a half day of debugging this appears to be the culprit. I downloaded py.test and tried it as well, and while it also failed with a similar error to nose, it gave me a crapload of output to look at, and OptionParser is definitely the problem. My only question now is how the heck to get around it. I guess for now I can just wrap up the optparse code in a function and stub that out, or monkeypatch the parser object I create at the module level. It’s a little disappointing that, with all the handwaving and hype around testing, there seems to be very little about what would seem like a *really* common caveat around on the ‘net. Are people just not testing optparse code?

    Anyway, my code’s the better for it in the end. This code shouldn’t really be floating in module-space like that anyway.

  • delijati

    same problem … fixed it by removing “functools” from install_requiers in python2.6

  • dean

    Hopefully you’ve figured this out by now, but for any others who stumble upon this page, here’s how I fixed it:

    I was importing one of my modules into the testing module. Turns out there was code outside of any function in that module, and an error there. I soon as I commented that out, Nose worked fine.