Skip to content Skip to sidebar Skip to footer

Django Testing External Script

I want to perform testing on a script that interacts with my Django application, namely the database. Normally, when we want to test something in Django we simply fire up the built

Solution 1:

I would suggest to use a different test runner.

You can do pip install django-nose and then set the following setting in your test_settings.py

TEST_RUNNER = `django_nose.NoseTestSuiteRunner`

Now you can run the tests with

./manage.py test --settings=yourproject.test_settings.py 

and the Nose testrunner will search all subfolders for folders called tests and in those folders it will search for files that end with _tests.py (and in those files it will search for classes that derive from TestCase, as usual).

So your project structure should look something like this:

- Project-Root/
  - Your-Non-App-Code/
    -__init__.py
    - non_app_code.py
    - tests/
      -__init__.py
      - non_app_code_tests.py

For more info on how to install django-nose, check their Github repo: https://github.com/django-nose/django-nose

Post a Comment for "Django Testing External Script"