3

I am running into issues with the Django (1.10.6) Test Runner being unable to find my tests. I am using Python 3.6.

The following works:

python manage.py test apps.foo

but this does not:

python manage.py test

My project structure looks as follows:

apps/
  foo/
    migrations/
    __init__.py
    admin.py
    apps.py
    models.py
    tests.py
    urls.py
    views.py
manage.py

And tests.py looks like this:

from django.test import TestCase


class ConfirmationTests(TestCase):
    def setUp(self):
        pass

    def test_email_confirm(self):
        pass

In my settings.py:

INSTALLED_APPS = (
  ...
  'apps.foo',
)

Is there any reason why the Test Runner would fail to pick up my tests?

Nathan
  • 1,897
  • 2
  • 15
  • 16

3 Answers3

13

I found the issue. As suspected it was something dumb.

I was missing a __init__.py in my apps directory.

apps/
  foo/
    migrations/
    __init__.py
    admin.py
    apps.py
    models.py
    tests.py
    urls.py
    views.py
  __init__.py <-- the offender
manage.py
Nathan
  • 1,897
  • 2
  • 15
  • 16
1

A couple other places to look:

  • Test filenames should start with test
  • The methods within the tests should start with test
  • If you're using a tests directory be sure to add __init__.py to the those test folders
jmunsch
  • 22,771
  • 11
  • 93
  • 114
0

Just for the record: I was having the same symptom because there was an extra __init__.py file in the project's directory (the same directory that contains manage.py)

Applications to test were found but then I'd get an error that . could not be imported.

RobM
  • 1,005
  • 11
  • 13