Opened 2 years ago

Closed 2 years ago

#20004 closed Cleanup/optimization (fixed)

move test helpers out of TransactionTestCase

Reported by: zalew Owned by: zalew
Component: Testing framework Version: 1.5
Severity: Normal Keywords: testing
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

django.test.testcases.TestCase inherits from TransactionTestCase, so when django.db is not used in the project, it complains during testing about "ImproperlyConfigured: settings.DATABASES". A solution is to use SimpleTestCase (which TransactionTestCase inherits from), but this class doesn't contain the useful test helpers currently located in TransactionTestCase, which aren't in any way related to db handling:

  • assertRedirects
  • assert(Not)Contains
  • assertFormError
  • assertTemplate(Not)Used
  • _urlconf_setup(teardown).

Proposal: move them out either to SimpleTestCase, or a separate class other tests (including TransactionTestCase) can inherit from, so they can be used in non-db test cases.

ref: https://github.com/django/django/blob/master/django/test/testcases.py

Change History (3)

comment:1 Changed 2 years ago by zalew

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Status changed from new to assigned

comment:2 Changed 2 years ago by claudep

  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 2 years ago by Ramiro Morales <cramm0@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In 0a50311063c416ec4d39f518e8d8110dd7eddbdf:

Fixed #20004 -- Moved non DB-related assertions to SimpleTestCase.

Thanks zalew for the suggestion and work on a patch.

Also updated, tweaked and fixed testing documentation.

Note: See TracTickets for help on using tickets.
Back to Top