LA Hattersley
LA Hattersley

Reputation: 249

Testing with Nose. Why am I getting "ImportError: No module named bin.app"

I'm currently on the last exercise (EX52) of Learn Python The Hard Way and I'm using Nose to test out the code (the exercise is to expand Nose testing to test out more of the code).

This is my file structure

bin
    app.py
gothonweb
    __init__.py
    map.py
sessions
tests
    map_tests.py
    app_tests.py

The sample code tests out the map.py file using the map_tests.py code.

from nose.tools import *
from gothonweb.map import *

def test_room():
    central_corridor = Room("Central Corridor" ... 

So I thought I'd expand this by creating a second test file, called app_tests.py that tested the app.py file. It contains this code

from nose.tools import *
from bin.app import *

def test():
    pass

When I run nosetests I get this error: ImportError: No module named bin.app

What am I doing wrong?

Upvotes: 2

Views: 6525

Answers (2)

Adam Smith
Adam Smith

Reputation: 54223

Since you don't have a __init__.py in your bin directory, it's just a directory, not a package. Since it's not a package, you can't look into the package to find the bin module.

From your parent directory, do

touch bin/__init__.py

on Mac/Linux, or

type NUL>bin\__init__.py

on Windows

Upvotes: 1

Josh J
Josh J

Reputation: 6893

From your directory structure you can see that bin is not a python package. It is a directory that contains a python module named app as referenced by app.py. Python packages have an __init__.py file inside of folders. I could explain in more detail but it would probably be better to post a link for you to reference.

http://docs.python-guide.org/en/latest/writing/structure/

Upvotes: 4

Related Questions