Login

Zope testing django layer

Author:
grahamcarlyle
Posted:
January 25, 2008
Language:
Python
Version:
.96
Tags:
testing tests test zope.testing
Score:
0 (after 0 ratings)

zope.testing is a test framework and test runner, similar to the django test runner and nose.

This snippet is a Layer class which you can assign as a layer attribute of your test suite to initialise and clean up the django test environment appropriately and to reset the test database between tests.

for example:

tests/suite.py

import unittest

from zope.testing import doctest

def test_suite():
    suite = doctest.DocFileSuite("models.txt")
    suite.layer = DjangoLayer
return suite

runtests.py

import os
from zope.testing import testrunner

os.environ['DJANGO_SETTINGS_MODULE'] = 'project.settings'
defaults = [
    '--path', 'tests',
    '--tests-pattern', '^suite$',
    '-c'
]
testrunner.run(defaults)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
class DjangoLayer(object):

    @classmethod
    def setUp(self):
        from django.conf import settings
        self.pre_existing_db_name = settings.DATABASE_NAME
        from django.test import utils
        utils.setup_test_environment()
        utils.create_test_db(verbosity=0, autoclobber=True)

    @classmethod
    def tearDown(self):
        from django.test import utils
        utils.destroy_test_db(self.pre_existing_db_name, verbosity=0)
        utils.teardown_test_environment()
    
    @classmethod
    def testTearDown(self):
        from django.core import management
        management.call_command('flush', verbosity=0, interactive=False)

More like this

  1. Syntax highlighting for tracebacks in console output by jezdez 2 years, 10 months ago
  2. Test runner that installs 'tests' packages as apps by adrian_lc 1 year, 9 months ago
  3. Test runner with coverage by nicklane 7 years, 2 months ago
  4. Thumbnails in admin using django-thumbnails-works by dperetti 4 years, 6 months ago
  5. save image from url to django ImageField by kriwil 3 years, 8 months ago

Comments

Please login first before commenting.