Django testing external script

I want to do testing on a script that interacts with my Django application, namely the database. Usually, when we want to test something in Django, we just run the built-in test suite. With this suite of tests, we even get nice command line switches, like overriding the builtin settings.py

with a different settings file:

python manage.py test myApp --settings='settings_test'

      

Here's the problem:

1) I want to test the mentioned script which is not part of the application, so I don't know how to call the test suite using manage.py

. Is it possible? I.e:.

python manage.py test /path/myScript.py --settings='settings_test'

      

+3


source to share


1 answer


I would suggest using a different test runner.

You can do pip install django-nose

and then set the next parameter totest_settings.py

TEST_RUNNER = `django_nose.NoseTestSuiteRunner`

      

You can now run tests with

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

      



and the Nose tester will search all subfolders for folders named tests

and in those folders it will look for files ending with _tests.py

(and in those files it will look for classes that descend 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 information on how to install django-nose check their Github repository: https://github.com/django-nose/django-nose

+3


source







All Articles