Skip to main content
https://github.com/django-functest/django-functest/workflows/Python%20package/badge.svg https://readthedocs.org/projects/django-functest/badge/?version=latest

Helpers for creating high-level functional tests in Django, with a unified API for WebTest and Selenium tests.

Exploring django-functest makes me angry! Why? Because I’ve wasted so much time writing low-level, boilerplate-filled tests for the past few years instead of using it — jerivas

What is WebTest? Imagine a text-based, HTML-only browser that doesn’t load CSS, Javascript etc, operates directly on a WSGI interface in a synchronous fashion for performance and robustness, and is controlled programmatically.

What is Selenium? A tool that opens full browsers like Firefox and Chrome (with an isolated profile), and provides an API for controlling them.

For an idea of what writing tests with django-functest looks like in practice, you might be interested in the video in our writing tests interactively documentation.

Documentation

The full documentation is at https://django-functest.readthedocs.org.

Installation

Python 3.8 and later, Django 2.2 and later are required.

pip install django-functest

See also the dependencies documentation for important compatibility information.

Features

  • A simplified API for writing functional tests in Django (tests that check the behaviour of entire views, or sets of views, e.g. a checkout process).

  • A unified API that abstracts over both WebTest and Selenium - write two tests at once!

  • Many of the gotchas and difficulties of using WebTest and Selenium ironed out for you.

  • Well tested - as well as its own test suite, which is run against Firefox and Chrome, it is also used by Wolf & Badger for tests covering many business critical functionalities.

  • Supports running with pytest (using pytest-django) as well as Django’s manage.py test

Typical usage

In your tests.py:

from django.test import LiveServerTestCase, TestCase
from django_functest import FuncWebTestMixin, FuncSeleniumMixin, FuncBaseMixin


class ContactTestBase(FuncBaseMixin):
    # Abstract class, doesn't inherit from TestCase

    def test_contact_form(self):
        self.get_url("contact_form")
        self.fill(
            {
                "#id_name": "Joe",
                "#id_message": "Hello",
            }
        )
        self.submit("input[type=submit]")
        self.assertTextPresent("Thanks for your message")


class ContactWebTest(ContactTestBase, FuncWebTestMixin, TestCase):
    pass


class ContactSeleniumTest(ContactTestBase, FuncSeleniumMixin, LiveServerTestCase):
    pass

In this way, you can write a single test with a high-level API, and run it in two ways - using a fast, WSGI-based method which emulates typical HTTP usage of a browser, and using a full browser that actually executes Javascript (if present) etc.

The approach taken by django-functest is ideal if your web app is mostly a “classic” app with server-side rendered HTML combined with a careful sprinkling of Javascript to enhance the UI, which you also need to be able to test. If such an approach seems old-fashioned to you, have a look at htmx.org or hotwire and get with the new kids! (OK most of are actually quite old but we make fast web sites…)

Under the hood, the WSGI-based method uses and builds upon WebTest and django-webtest.

django-functest provides its functionality as mixins, so that you can have your own base class for tests.

Contributing and tests

See CONTRIBUTING.rst for information about running the test suite and contributing to django-functest.

Building on Mac OS

While this lxml bug is in effect lxml cannot handle certain unicode characters in HTML (or XML!) documents on Mac OS, including the emoji used in one of the files in the test suite.

Therefore, if you are affected by this bug, you will find that certain tests fail with the error lxml.etree.ParserError: Document is empty.

You will also find that lxml’s own test suite fails on your machine.

A workaround is to compile libxml2 yourself, which lxml will take care of for you. To do this, run the following:

` STATICBUILD=true python -m pip install lxml --force-reinstall --no-binary=:all: `

Paid support

Some of the maintainers are able to provide support on a paid basis for this Open Source project. This includes the following kinds of things:

  • Paying for bug fixes or new features (with the understanding that these changes will become freely available as part of the project and are not ‘owned’ by the person who paid for them).

  • Debugging or other support for integrating django-functest into your project.

  • Writing a test suite for you from scratch using django-functest.

If you are interested in these, you can contact the following developers:

Credits

This library was written originally by spookylukey, further improved by developers at Wolf & Badger, and released with the kind permission of that company.

Tools used in rendering this package:

Release files for django-functest 1.6.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-functest 1.6.2
File Size Uploaded
django_functest-1.6.2.tar.gz 78.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-functest 1.6.2
File Interpreter ABI Platform
django_functest-1.6.2-py3-none-any.whl Python 3 none any Details

Total release size: 104.0 kB

Release files / django_functest-1.6.2.tar.gz

Download URL django_functest-1.6.2.tar.gz
Size 78.6 kB
Tags Source
SHA-256 checksum
How to use checksums
c0e7f74722500b77def45dcba21a4ec9b8e8697c17775b47ab7b0d89b43db71f
BLAKE2b-256 checksum
How to use checksums
920d0b240210c4fd70511b209e881b9873cb265ea2ad27502ad8746a5bc16708
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.0

Release files / django_functest-1.6.2-py3-none-any.whl

Download URL django_functest-1.6.2-py3-none-any.whl
Size 25.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2f437ea8d46ecde4bef0a8c0336b600d74292734512ecbad452dc687e8094159
BLAKE2b-256 checksum
How to use checksums
0f3186a4ad9619df380c4975b9f732ad2245486fb693898c36c6f7aec27672f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.0

Release history Release notifications | RSS feed

This release

1.6.2 This release

2 release files

1.6.1

2 release files

1.6

2 release files

1.5.5

2 release files

1.5.4

2 release files

1.5.3

2 release files

1.5.2

2 release files

1.5.1

2 release files

1.5

2 release files

1.4.1

2 release files

1.4

2 release files

1.3

2 release files

1.2

2 release files

1.1.1

2 release files

1.1

2 release files

1.0.4

4 release files

1.0.3

3 release files

1.0.2

3 release files

1.0.1

3 release files

1.0

3 release files

0.2.1

3 release files

0.2.0

3 release files

0.1.9

3 release files

0.1.8

3 release files

0.1.7

3 release files

0.1.6

3 release files

0.1.5

3 release files

0.1.4

3 release files

0.1.3

3 release files

0.1.2

3 release files

0.1.1

1 release file

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page