How to spread django unit tests over multiple files?
Question:   * I have a python-django application
  * I'm using the [unit testing framework](https://docs.djangoproject.com/en/1.3/topics/testing/)
  * The tests are arranged in the file "tests.py" in the module directory
  * I'm running the tests via `./manage.py test app`

Now..

  * The `tests.py` file is getting rather large/complex/messy
  * I'd like to break `tests.py` up into smaller collections of tests...

How?


Answer: You can create `tests` folder with `___init___.py` inside (so that it becomes
a package). Then you add your split test .py files there and import all of
them in `___init___.py`.

I.e: Substitute the `test.py` file with a module that looks and acts like the
file:

Create a `tests` Directory under the app in question

    
    
    app
    app\models.py
    app\views.py
    app\tests
    app\tests\__init__.py
    app\tests\bananas.py
    app\tests\apples.py
    

Import the submodules into `app\tests\__init__.py`:

    
    
    from bananas import *
    from apples import *
    

Now you can use ./manage.py as if they were all in a single file:

    
    
    ./manage.py test app.some_test_in_bananas
    

Note that this approach is no longer valid from Django 1.6, see this
[post](http://stackoverflow.com/a/20932450/117194).

