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 3 years, 3 months ago
  2. Unittest: Compare max_size with column size of database by guettli 3 years, 9 months ago
  3. UnitTesting without create/destroy database by crucialfelix 3 years, 3 months ago
  4. TestSettingsManager: temporarily change settings for tests by carljm 3 years, 8 months ago
  5. Forcing unit test runner to abort after failed test by simonbun 5 years ago

Comments

(Forgotten your password?)