I’m working on the final exercise, and have a strange issue. I have previously had difficulties with running nosetests. My file structure is the same as laid out in ex 52:
/gothonweb
__init__.py
app.py
markup.py
planisphere.py
/static
/templates
layout.html
show_room.html
you_died.html
/tests
app_tests.py
planisphere_tests.py
app.py runs just fine on localhost in the browser, but when nosetests run I get a failure. The import statements in planisphere_tests.py are taken directly from the exercise:
from nose.tools import *
from gothonweb.planisphere import *
Traceback is:
File "/Users/Zeesy/hard_way/projects/gothonweb/app.py", line 3, in <module>
import planisphere
ModuleNotFoundError: No module named 'planisphere'
When run with:
from nose.tools import *
import planisphere
Traceback is:
File "/Users/Zeesy/hard_way/projects/gothonweb/tests/planisphere_tests.py", line 2, in <module>
import planisphere
ModuleNotFoundError: No module named 'planisphere'
As mentioned, app.py runs the local server with no problems and the game works perfectly in the browser. What is going on here?
I’m under the impression that if planisphere is a python file, then it can be considered a module and imported. So, from gothonweb.planisphere import * would import any class/module inside planisphere.py
Room is the class inside planisphere.py. When I change the line to from planisphere import Room, I get an internal server error and the page will not load. The nosetest also fails with ModuleNotFoundError: No module named 'planisphere'
Python always assumes an import is in the same directory. I believe the link explains that python will not import from outside the current directory.
I hope someone else can pop in and help. I know I couldn’t use pytest on files in a separate directories.
I’m confused about this, because in ex47, ex48 and ex49 the tests are in a tests folder, and the files being tested are in a subdirectory also called ex49 etc. These nosetests pass despite the different directories and the program not running (see previous post)
ie:
AH! I was missing an __init__.py from my /tests directory. This is what makes it a package. Now running into other issues but at least the original import statements work.
So the original import statement inside planisphere.py: