Django Testing Base

Latest Version Development Status Supported Python versions Django versions License Requirements Status Downloads

Django Testing Base provides base Test Case and mixin classes that encapsulate common testing operations and patterns. They do the "right" thing whether you're testing individual units of code or entire live pages using selenium.


  • Generate test data
  • Create and login users
  • Common assertions
  • Run selenium tests at different browser dimensions
  • Base implementation of Page Object pattern

An example unit test:

from testbase.unit import UnitTestCase

class TestMyView(UnitTestCase):
    def test_somethingWithAUser(self):
        user = self.createUser()
        self.assertLastContextValueEqual('context_var', user.username)

An example browser test using the Page Object pattern:

from testbase.browser import PageObject, BrowserTestCase

class MyPage(PageObject):
    _urlPattern = 'named_url_pattern'
    _pageName = 'My Super Page'

    def click_link(self):
        link = self.browser.find_element_by_id('link_to_another_page')

class TestMyPage(BrowserTestCase):
    _pageClass = MyPage
    _requiresLogin = True

    def __init__(self, methodName):
        self.thing = Thing.objects.create()
        self._urlFields['objectId'] =

    def test_linkGoesToOtherPage(self):
        OtherPage(self.browser, otherPageField = 'some value')


Install Django Testing Base using pip:

pip install django-testing-base



The project is licensed under the MIT license.