6

I'm having a problem running django doctests with django-nose. Unit tests added to a /tests directory are running fine, but doctests are not.

I am trying to run doctests on my "season" module:

python manage.py test season

and get this output:

nosetests --verbosity 1 season --with-doctest
Creating test database for alias 'default'...

----------------------------------------------------------------------
Ran 0 tests in 0.001s

OK
Destroying test database for alias 'default'...

I'm just trying a basic doctest to try to get this to work, e.g.:

    """
    >>> 1+1 == 2
    True
    """

This is in my models.py. I've tried other doctests actually testing the code and still don't see any tests run. When I run with --verbosity 3, I see one line that may be the issue:

nose.selector: INFO: <models.py path> is executable; skipped

I couldn't find any more info on what this means though.

Relevant snippets from settings.py:

INSTALLED_APPS = (
    'south',
    'django_nose',
    'season',
)

# Django-nose configuration
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
NOSE_ARGS = ['--with-doctest']

django_nose is after south in INSTALLED_APPS as specified in the django-nose documentation. I'm using the --with-doctest argument as suggested here: Nose not running Django doctests, and have updated my django-nose to the latest as suggested here: Why isn't django-nose running the doctests in my models?

These are the versions I am using:
django 1.3
python 2.7.1
django-nose 0.1.3
nose 1.1.2

I feel like I'm missing some basic setup here. Let me know if any other info is needed. Any help is appreciated, thanks!

Community
  • 1
  • 1
rrw4
  • 61
  • 2

3 Answers3

4

I realize that the OP specified 1.3, but since this answer comes up in a search for 'django doctests do not run' here's my answer for 1.6 from one of the answers in Django doctests in views.py. in this version of Django doctests are not automatically included, so in $APP/tests.py you need:

import doctest
def load_tests(loader, tests, ignore):
    tests.addTests(doctest.DocTestSuite())
    return tests

[this only finds the doctests in tests.py itself; to have it run doctests on other modules, say myapp/models.py, you need to from myapp import models and tests.addTests(doctest.DocTestSuite(models))]

Community
  • 1
  • 1
jcomeau_ictx
  • 37,688
  • 6
  • 92
  • 107
  • 1
    That would make nose irrelevant (which is fine with me—I was only trying it because it was supposed to solve this problem), but STILL isn't finding any doctests. I can specify the specific modules, but that's not automatic... – Auspex Apr 15 '14 at 17:10
  • 1
    right, the above only finds the doctests in tests.py itself. – jcomeau_ictx Apr 15 '14 at 18:14
  • 1
    Great! Just confirming that this still works in Django 3.2 – cxxl Dec 01 '21 at 18:10
2

The verbosity message is telling you your models.py file is being ignored because it's executable. This means you need to do:

chmod -x models.py

Unless you have a specific reason for that file to be set as executable, in which case adding --exe to your NOSE_ARGS should be sufficient.

unode
  • 9,321
  • 4
  • 33
  • 44
1

nosetests --verbosity 1 season --with-doctest

Usage: manage.py test [options] [appname ...]

Perhaps you just need to move season to then end.

dm03514
  • 54,664
  • 18
  • 108
  • 145
  • I run "manage.py test season", with the --with-doctest argument in the NOSE_ARGS. If I remove --with-doctest from NOSE_ARGS, and run "manage.py test --with-doctest season", I get the same result. So I think this is how "manage.py test" will run nosetests. Any other possibilities? – rrw4 Oct 22 '11 at 18:15