doctest not running in an app

2 views
Skip to first unread message

davenaff

unread,
May 10, 2008, 6:49:23 PM5/10/08
to Django users
I've just begun using doctests and when I run manage.py test appname,
the doctests in the models.py file aren't running.

I have other apps in the project that have doctests that run fine.

I also have taken the models in this app and pasted them into a
different app. The doctests run fine in that app (so, I believe the
doctest syntax is correct).

I have a tests.py in the app with unit tests that work as expected. I
deleted the file and retried to run the test and it still did not run.

I'm at a loss here. Any ideas?
Dave

davenaff

unread,
May 10, 2008, 8:49:35 PM5/10/08
to Django users
As I dig into this, I've found that the problem is that the classes in
my models.py file are not being recognized as being from the module.

Specifically, the _from_module function in the DocTestFinder class in
_doctest.py is failing to identify the module as internal.

Upon closer inspection this statement (line 897 in _doctest.py)
returns false:
module.__name__ == object.__module__

When I print the values, they look like this:
print module.__name__
projectname.appname.models

print object.__module__
appname.models

So, I need to figure out why object.__module__ isn't providing the
full path.

Any ideas?

Dave

davenaff

unread,
May 10, 2008, 9:00:06 PM5/10/08
to Django users
It is probably also worth noting that _doctest returns correct
(projectname.appname.models) object.__module__ values for Managers.

phillc

unread,
May 10, 2008, 10:18:06 PM5/10/08
to Django users
can we see your models.py?

davenaff

unread,
May 10, 2008, 10:44:55 PM5/10/08
to Django users
Thanks for the note. I actually just resolved this.

I had created a module that resided in the appname directory, and was
importing via: from appname.models import *

I changed the import to:
from projectname.appname.models import *

And tests were correctly picked up.

I think this is a bug? I shouldn't need to include the projectname in
modules that are fully contained within an app.

davenaff

unread,
May 11, 2008, 12:18:07 AM5/11/08
to Django users
I take that back. Not resolved.

My directory structure looks like this:

/appname/models.py
/appname/utils/__init__.py (empty)
/appname/utils/util1.py

in util1.py, I do this:
from appname.models import Class1, Class2

This causes the doctests in models.py to not run.

If I change util1.py to:
from projectname.appname.models import *

the doctests in models.py are run, but I get execution errors in
util1.py.
Reply all
Reply to author
Forward
0 new messages