views:

400

answers:

3

Is there any reason why Nose wouldn't be able to find tests in Ubuntu 9.04? I'm using nose 0.11.1 with python 2.5.4. I can run tests only if I explicitly specify the filename. If I don't specify the filename it just says 0 tests.

The same project runs tests fine on my Mac, so i'm quite stumped.

+5  A: 

This behavior is almost certainly because your files are not named in accordance with nose's test matching behavior. From the nose docs:

nose collects tests automatically from python source files, directories and packages found in its working directory (which defaults to the current working directory). Any python source file, directory or package that matches the testMatch regular expression (by default: (?:^|[b_.-])[Tt]est) will be collected as a test (or source for collection of tests).

Emphasis was mine.

Some example names that would match:

  • TestFoo.py
  • Foo-Test.py
  • Foo_Test.py
  • Foo.Test.py (note that this one will try to import Foo, and will raise an exception if it cannot)

A name that looks like it would match, but actually does not:

  • FooTest.py

If you just rename your files you should be good to go.


Update: Have you read this blog post? I wasn't able to tell from the details you've posted, but maybe your test directories are missing their __init.py__ files?

... make sure that your “tests” directories are actually modules (they have an empty __init__.py file).

Mark Rushakoff
will try that... the thing is, the same files bet picked up on my Mac... doesn't nose use the same matcher across all platforms?
Sudhir Jonathan
Your NOSE_TESTMATCH environment variable might be set differently, or take a look at nose/config.py. http://code.google.com/p/python-nose/wiki/FindingAndRunningTests
Mark Rushakoff
The tests work when I import the test file in the __init__.py and specify the module to run. Not otherwise. The exact same directory and commands work fine on my Mac, though, even without explicitly specifying the directory. Still not able to figure it out.
Sudhir Jonathan
+1  A: 

The other thing which always gets me with nose is that it won't run tests in executable files. I'm not exactly sure why that would make a difference across Mac/Ubuntu, but it's worth a shot.

Make sure that the scripts didn't somehow get chmod +x'd on the Mac… And if they did, fix them with chmod -x $(find tests/ -name '*.py').

David Wolever
Still not working... and the problem is on ubuntu, not on the mac.
Sudhir Jonathan
Nose doesn't by default look for tests in executable modules only on windows platform...on mac/ubuntu he'd have to be using --noexe switch for that to happen
atlantis
worked for me on windows
Matteo Caprari
A: 

On a hunch, Ubuntu running in a VM on Mac? Which one?

atlantis
Ah... nope. Ubuntu on my desktop (can't afford an iMac) and an office provided macbook pro.
Sudhir Jonathan
I share my codebase between then on github, if anyone else is thinking of asking. github.com/sudhirj/mappr , if you want to try it out yourself.
Sudhir Jonathan
this is not an answer, it's a comment.
hminaya
Did not have enough rep to add a comment as of then...
atlantis