1

I have a few functional tests for an app I am developing. For every test, I need to create an admin user, and then also a few profiles of users of the app. Creating the admin and the user profiles does not take too long if you are running one test only, but it adds up when I run all tests, which is required every time we add a new feature to the add.

I have a Python file with the following:

import unittest, sys

from django.conf import settings

print("DEV_ENV: "+str(settings.DEV_ENV))
print("TEST_ENV: "+str(settings.TEST_ENV))
print("PROD_ENV: "+str(settings.PROD_ENV))

from case1test import Case1Test
from case2test import Case2Test
from case3test import Case3Test
from case4test import Case4Test


if __name__ == '__main__':
    unittest.main()

I would like to create the admin and user profiles ONCE for all functional tests. Can someone give me some advice on how to proceed? The app is developed using Django 1.6, so the --keepdb option is not available.

1
  • What specific method did you use to determine that of all the things the Django test runner does to set up a test, the creation of the user profiles is what takes a substantial portion of the set up time? Commented Oct 31, 2014 at 20:08

1 Answer 1

1

They are many ways to do that :

  • With fixtures:
    Add a fixture file in yourapp/fixtures/, I suggest you to dump a new one with ./manage.py dumpdata yourapp.yourmodel --pks=<instance_id>.
    Simply load needed fixture in your tests.
    With little fixture loading is fast but if you deal with bigger sizes you can use Django-nose and hisFast Fixtures feature

  • With Factory Boy:
    A library for building set of objects/models with (±) small declaration

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.