0

Django 1.6.10 cannot find test modules located outside my apps when running any of these code (ref: https://docs.djangoproject.com/en/1.6/topics/testing/overview/#running-tests)

./manage.py test tests/app1/
./manage.py test tests/app1/test_views

I keep getting these errors

django.core.exceptions.ImproperlyConfigured: App with label tests/app1/ could not be found

django.core.exceptions.ImproperlyConfigured: App with label tests/app1/test_views could not be found

Here is my project structure:

- project
    - app1
        - __init__.py
        - models.py
        - views.py
        - forms.py
        - admins.py
    - app2
        - ..as per above
    - tests
        - __init__.py (blank)
        - app1
           - __init__.py (blank)
           - test_views.py
           - test_forms.py
        - app2
           - __init__.py (blank)
           - test_views.py
           - test_walkthrough.py    

I read Django Discovery runner a few times and still cannot find out where did I go wrong. Any help please - what do I miss

Replacing / with . gives the same error however when execute

./manage.py test tests.app1.test_views.MyTestCase
./manage.py test tests.app1.test_views.MyTestCase.test_mymethod   

I get ValueError.

ValueError: Test label  'tests.app1.test_views.MyTestCase.test_mymethod' should be of the form app.TestCase or app.TestCase.test_method

Further update: I finally got it to work when adding --testrunner='django.test.runner.DiscoverRunner' to the command line. As per Django doc, any of these patterns works now (using / is a way of providing a path to a directory to discover tests below that directory):.

./manage.py test --testrunner='django.test.runner.DiscoverRunner' tests.app1
./manage.py test --testrunner='django.test.runner.DiscoverRunner' tests.app1.test_views.MyTestCase
./manage.py test --testrunner='django.test.runner.DiscoverRunner' tests/app1/

Still do not know why I have to provide --testrunner value. I am using Mezzanine in my code too and have double confirmed that settings.TEST_RUNNER is pointing to django.test.runner.DiscoverRunner

Can anyone help explaining why do I need --testrunner flag in django 1.6? Thank you in advance.

green
  • 226
  • 2
  • 12
  • Did my solution not work for you? – rnevius Mar 16 '15 at 14:22
  • Replacing / with .(dot) did not work. I was using that convention before when I have each app tests under its own directory. I prefer to have Test separate from my code and thus when changing to this file structure, django Discovery does not seem to find the tests. – green Mar 17 '15 at 05:31

1 Answers1

3

You should be referring to them as modules, not paths:

./manage.py test tests.app1
./manage.py test tests.app1.test_views

Read more about running tests in the docs.

rnevius
  • 26,578
  • 10
  • 58
  • 86
  • This does not work. I also tried configure configuring (which I don't think it is required given that i am using 1.6.10) TEST_DISCOVER_ROOT = os.path.join(BASE_PATH, "tests") and check that it is pointing to correct path in my settings.py. Still no joy. – green Mar 17 '15 at 05:44
  • This *does* work. This is how Python references modules. At the very least, doing this should raise a different error. What error do you get when you use this? – rnevius Mar 17 '15 at 06:15
  • I get this error: django.core.exceptions.ImproperlyConfigured: App with label tests could not be found. Between, must I include this tests directory in INSTALLED_APPS – green Mar 17 '15 at 09:48
  • I tried adding tests dir to INSTALLED_APPS in settings.py. Then executing ./manage.py test tests.app1.test_views I get this error: ValueError: Test label 'tests.app1.test_views' does not refer to a test. But if i move test_views.py under app1/tests directory then it works ok. I thought with Django 1.6, it should discover test even if tests are not in app dir. – green Mar 17 '15 at 09:56
  • got it to work now by adding --testrunner='django.test.runner.DiscoverRunner' Not sure why that is required even though the TEST_RUNNER is pointing to django.test.runner.DiscoverRunner – green Mar 18 '15 at 16:14