Search code examples
pythondjangounit-testingdjango-unittest

Execute Unittest in Django


I have written a small unit test for my django view .My project structure is like

Project_name/

         apps/

              module1/
                      tests.py
              module2/
                      tests.py

this is my dir structure i am executing the tests by using the command :

$python manage.py test_coverage module1 module2 -v2

then it executing the test nicely but now i have change dir structure little bit i have created a new directory tests/ in that i have kept my all test files

project_name/

       apps/

            module1/
                    tests/
                         test_basic.py
                         test_detail.py

Now i can able to execute those tests which are in dir with the same above command ,is their is any alternative way to execute such tests?


Solution

  • The simplest solution is to add __init__.py file to tests/ package containing following lines:

    from .test_basic import *
    from .test_detail import *
    

    And then run all the tests with:

    $ python manage.py test module1