{"id":7182,"library":"django-webtest","title":"Django WebTest","description":"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.","status":"active","version":"1.9.14","language":"python","source_language":"en","source_url":"https://github.com/django-webtest/django-webtest","tags":["django","testing","webtest","functional testing","integration testing","wsgi"],"install":[{"cmd":"pip install django-webtest","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core framework integration; specific Django versions are supported per django-webtest release.","package":"django"},{"reason":"The underlying functional testing library that django-webtest integrates with Django.","package":"webtest"}],"imports":[{"wrong":"from django_webtest import WebTest","symbol":"WebTest","correct":"from django_webtest import WebTest"}],"quickstart":{"code":"from django_webtest import WebTest\nfrom django.urls import reverse\n\nclass MyBasicTests(WebTest):\n    fixtures = ['users'] # Optional: if you need initial data, e.g., for login\n\n    def test_homepage_access(self):\n        # Simulate a GET request to the homepage\n        resp = self.app.get(reverse('home_page'))\n        self.assertEqual(resp.status_code, 200)\n        self.assertIn('Welcome', resp.text)\n\n    def test_login_form_submission(self):\n        # Simulate login as a specific user\n        login_page = self.app.get(reverse('login_page'))\n        form = login_page.form\n        form['username'] = 'testuser'\n        form['password'] = 'testpassword'\n        resp = form.submit().follow()\n        self.assertEqual(resp.status_code, 200)\n        self.assertIn('Logged in as testuser', resp.text)\n\n    def test_authenticated_page(self):\n        # Make an authenticated request using the user argument\n        user_resp = self.app.get(reverse('profile_page'), user='testuser')\n        self.assertEqual(user_resp.status_code, 200)\n        self.assertIn('User Profile for testuser', user_resp.text)","lang":"python","description":"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."},"warnings":[{"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.","message":"Starting 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.","severity":"breaking","affected_versions":">=1.9.13"},{"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`.","message":"As 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.","severity":"breaking","affected_versions":">=1.9.12"},{"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`.","message":"Unlike 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.","severity":"gotcha","affected_versions":"all"},{"fix":"For JavaScript-dependent interactions, consider using a browser automation tool like Selenium or Playwright alongside your functional tests.","message":"The `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.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"search_vec":"'activ':50 'around':34 'bick':16 'compat':57 'django':1,4,20,36,61,65 'django-webtest':3 'django.test.testcase':27 'django_webtest.webtest':29 'enabl':39 'ensur':56 'framework':23 'frequent':53 'function':43,68 'high':41 'high-level':40 'ian':15 'instant':12 'integr':13,45,70 'interfac':38 'latest':60 'level':42 'librari':9,48 'maintain':51 'offer':25 'provid':11 'python':8,63 'subclass':28 'test':22,46,66,69,71 'updat':54 'version':64 'webtest':2,5,18,67 'webtest.testapp':33 'wrap':31 'wsgi':37,72","created_at":"2026-04-16T13:47:05.375686+00:00","updated_at":"2026-04-16T13:47:05.375686+00:00","problems":{"verify_error":"Traceback (most recent call last):\n  File \"<string>\", line 1, in <module>\n  File \"/tmp/tmpszl5bg11/venv/lib/python3.12/site-packages/django_webtest/__init__.py\", line 4, in <module>\n    from django.conf import settings\nModuleNotFoundError: No module named 'django'"},"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"1.9.14","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/django-webtest/django-webtest","docs":null,"changelog":"https://github.com/django-webtest/django-webtest/blob/master/CHANGES.rst","pypi":"https://pypi.org/project/django-webtest/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing","web-framework"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"import_fail","verified_at":"2026-07-03","last_verified":"2026-07-03","next_check":"2026-07-10","install_tag":null}}