Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

__init__.py in project folder breaks nose tests

project tree:

.
|-- bar.py
`-- test
    |-- __init__.py
    `-- test_bar.py

bar.py:

def dumb_true():
    return True

tests/test_bar.py:

import bar

def test_bar_true():
        assert bar.dumb_true()

I can run nosetests from inside the project or its test directory. If I add an empty __init__.py to the project folder, however, I can no longer run nosetests from inside the test directory, which doesn't make any sense to me.

.
|-- bar.py
|-- __init__.py  <-- new, empty file, ruining everything
`-- test
    |-- __init__.py
    `-- test_bar.py

Can anyone explain to me what's going on here?

I've read extensively on this topic - through nose documentation/man pages and all over the internet; but it looks very confusing to me how this all resolves!

like image 971
Gary Fixler Avatar asked Oct 22 '22 03:10

Gary Fixler


1 Answers

Looks like your question was answered here.

You've got an __init__.py in your top level directory. That makes it a package. If you remove it, your nosetests should work.

If you don't remove it, you'll have to change your import to import dir.foo, where dir is the name of your directory.

like image 162
Rooks103 Avatar answered Oct 27 '22 10:10

Rooks103