Unit Tests That Write Fixtures

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import unittest
import os
from django.core import serializers
from django.db.models import get_apps
from django.conf import settings

from app.models import ...

class MyTestCase(unittest.TestCase):
    def setUp(self):
        self.apps = get_apps()
    
    def test...(self):
        ...
        
    def tearDown(self):
        objects = []
        for app in self.apps:
            for model in get_models(app):
                objects.extend(model._default_manager.all())

        out = open(os.path.join(settings.SVN_DIR,'fixtures','tests.json'), 'w')
        out.write(serializers.serialize('json',objects))
        out.close()

More like this

  1. Unit Test Profiling by justquick 4 years, 3 months ago
  2. Unittest: Compare max_size with column size of database by guettli 4 years, 9 months ago
  3. UnitTesting without create/destroy database by crucialfelix 4 years, 3 months ago
  4. Fail Faster: unsafe_test Management Command by majgis 9 months, 2 weeks ago
  5. Proper fixtures loading in south data migrations by JustDelight 2 months, 3 weeks ago

Comments

(Forgotten your password?)