[Answered ]-How to separate test types using Django

1👍

The way my company organises tests is to split them into two broad categories. Unit and functional. The unit tests live inside the Django test discovery. manage.py test will run them. The functional tests live outside of that directory. They are run either manually or by the CI. Buildbot in this case. They are still run with the unittest textrunner. We also have a subcategory of functional tests called stress tests. These are tests that can’t be run in parallel because they are doing rough things to the servers. Like switching off the database and seeing what happens.

The CI can then run each test type as a different step. Tests can be decorated with skipif.

It’s not a perfect solution but it is quite clear and easy to understand.

1👍

My way for this look like this:

  1. Create folder tests in your app folder
  2. Create py files with test cases (unit_test.py, functional_test.py etc.)
  3. Create __init__.py in test directory with:

    from unit_tests import *
    
    from functional_tests import *
    

And you can run you test from manage.py like this:

manage.py test # run all tests (include django tests)
manage.py test my_app # run all my tests
manage.py test my_app.UnitTestCase # run specific test case

Leave a comment