Testing only a project in Django

When I try to run python manage.py test in my Django project (1.4), I get an error:

 ERROR: test_site_profile_not_available (django.contrib.auth.tests.models.ProfileTestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/slacy/src/tmp/env/local/lib/python2.7/site-packages/django/contrib/auth/tests/models.py", line 29, in test_site_profile_not_available del settings.AUTH_PROFILE_MODULE File "/home/slacy/src/tmp/env/local/lib/python2.7/site-packages/django/utils/functional.py", line 215, in __delattr__ delattr(self._wrapped, name) AttributeError: AUTH_PROFILE_MODULE 

This is documented in a Django bug, with a recommendation to test only specific applications, and not all. However, there are no applications in my project, models.py simply at the root of the project. To test a specific application in Django, it looks like this :

 $ ./manage.py test animals Note that we used animals, not myproject.animals. 

means that it is not possible to determine the root directory for verification. How can I check only the project directory?

Note that this error is part of a more detailed discussion about finding test modules.

+6
source share
2 answers

I would recommend using django-discover-runner . It allows you to specify the full dotted path for testing.

If you just run the test. /manage.py, it will detect and run all the tests under the setting TEST_DISCOVER_ROOT (path to the file system). If you run. /manage.py test full.dotted.path.to.test_module, it will run tests in this module (you can also pass multiple modules). If you give it one point path to the package (e.g. a Django application), for example. /manage.py test myapp, and this package itself does not contain any tests, it will check detection in all submodules of this package.

+3
source

Create a new directory called apps, move the entire application into it minus settings.py, manage.py, urls.py and any other django-admin.py startproject added by default, and then run

 ./manage.py test apps 

In the future, avoid storing the entire application in one directory. Divide it into sub-applications based on functionality, for this very reason

0
source

Source: https://habr.com/ru/post/915866/


All Articles