Registry / testing / django-webtest

django-webtest

JSON →
library1.9.14pypypiunverified

django-webtest is a Python library that provides instant integration of Ian Bicking's WebTest with Django's testing framework. It offers a `django.test.TestCase` subclass (`django_webtest.WebTest`) that wraps a `webtest.TestApp` around the Django WSGI interface, enabling high-level functional and integration testing. The library is actively maintained, with frequent updates to ensure compatibility with the latest Django and Python versions.

pip install django-webtest
INSTALL
IMPORT
SIG · DJANGO-WEBTEST
D
django-webtest
testingpythonv1.9.14
Install
2.1s avg
Import
—
Disk
19MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v1.9.14 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 20.9MB
glibc
py 3.10–3.920 runs
installs and imports cleanly · install 2.1s · import 0.000s · 21MB
19MB installed
● package 19MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

WebTest
✓ from django_webtest import WebTest
✗ from django_webtest import WebTest

This quickstart demonstrates creating a basic functional test using `django_webtest.WebTest`. It shows how to perform GET requests, interact with forms, simulate user login, and assert properties of the response, such as status code and content. Remember to replace `home_page`, `login_page`, and `profile_page` with actual URL names from your Django project. The `fixtures` attribute is optional and allows loading initial data for tests.

from django_webtest import WebTest from django.urls import reverse class MyBasicTests(WebTest): fixtures = ['users'] # Optional: if you need initial data, e.g., for login def test_homepage_access(self): # Simulate a GET request to the homepage resp = self.app.get(reverse('home_page')) self.assertEqual(resp.status_code, 200) self.assertIn('Welcome', resp.text) def test_login_form_submission(self): # Simulate login as a specific user login_page = self.app.get(reverse('login_page')) form = login_page.form form['username'] = 'testuser' form['password'] = 'testpassword' resp = form.submit().follow() self.assertEqual(resp.status_code, 200) self.assertIn('Logged in as testuser', resp.text) def test_authenticated_page(self): # Make an authenticated request using the user argument user_resp = self.app.get(reverse('profile_page'), user='testuser') self.assertEqual(user_resp.status_code, 200) self.assertIn('User Profile for testuser', user_resp.text)
Debug
Known issues
breakingStarting with django-webtest 1.9.13, support for Django 3.x and 4.1 has been dropped. Ensure your Django version is supported by the installed django-webtest version.
fix
Upgrade Django to a supported version (e.g., Django 4.2 or 5.x) or downgrade django-webtest if legacy Django versions must be maintained.
affects: >=1.9.13
breakingAs of django-webtest 1.9.12, the `assertFormError` method is no longer compatible. This is due to changes in Django's internal handling of form errors.
fix
Migrate your tests to use alternative methods for asserting form errors, such as inspecting `response.html` with Beautiful Soup or checking specific text in `response.text`.
affects: >=1.9.12
gotchaUnlike Django's native test client, django-webtest does NOT suppress CSRF checks by default. This means missing CSRF tokens in forms will cause tests to fail with HTTP 403 Forbidden errors.
fix
Ensure that your forms include a `{% csrf_token %}` in your templates. If you need to explicitly disable CSRF for a specific view in tests, configure Django's `MIDDLEWARE` setting or use a pytest fixture (if using pytest-django) to unpatch settings, if supported by `django-webtest`.
affects: all
gotchaThe `click` method on a WebTest response object will not work for links that rely on JavaScript for their action (e.g., `onclick` attributes without an `href`). WebTest does not execute JavaScript.
fix
For JavaScript-dependent interactions, consider using a browser automation tool like Selenium or Playwright alongside your functional tests.
affects: all
Upgrade
Version history
1.9.14latest on PyPI · released Oct 6, 2025
Audit
Dependencies
djangorequiredCore framework integration; specific Django versions are supported per django-webtest release.
webtestrequiredThe underlying functional testing library that django-webtest integrates with Django.
Agent activity
11 hits · last 30 days
node
10
Resources
django-webtest — pip install django-webtest · libregistry