Proposal: move non-db tests out of TransactionTestCase

46 views
Skip to first unread message

zalew

unread,
Mar 7, 2013, 3:32:22 PM3/7/13
to django-d...@googlegroups.com
Hi

I'm currently working on a project where I don't use db.* and I met a problem during testing. As django.test.testcases.TestCase [1] inherits from TransactionTestCase, it complains about "ImproperlyConfigured: settings.DATABASES". A solution is to fall back to SimpleTestCase (which TransactionTestCase inherits from), but this class doesn't contain useful test helpers, which aren't in any way related to db handling:

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

Is there a reason why these functions were bound to a transaction handling test class instead of SimpleTestCase?

My proposal is to move them out either to SimpleTestCase, or a separate class other tests (including TransactionTestCase) can inherit from. I have experimentally written a SimpleTestCase based class for my needs, but I haven't yet tested it against the Django suite.

What do you think? If you agree and/or have some ideas, I will submit an issue and work on a patch proposal.

[1] https://github.com/django/django/blob/master/django/test/testcases.py

Cheerz,
Jakub Zalewski

Carl Meyer

unread,
Mar 7, 2013, 3:34:05 PM3/7/13
to django-d...@googlegroups.com
On 03/07/2013 01:32 PM, zalew wrote:
> I'm currently working on a project where I don't use db.* and I met a
> problem during testing. As django.test.testcases.TestCase [1] inherits
> from TransactionTestCase, it complains about "ImproperlyConfigured:
> settings.DATABASES". A solution is to fall back to SimpleTestCase (which
> TransactionTestCase inherits from), but this class doesn't contain
> useful test helpers, which aren't in any way related to db handling:
>
> * assertRedirects
> * assert(Not)Contains
> * assertFormError
> * assertTemplate(Not)Used
> * _urlconf_setup(teardown).
>
> Is there a reason why these functions were bound to a transaction
> handling test class instead of SimpleTestCase?
>
> My proposal is to move them out either to SimpleTestCase, or a separate
> class other tests (including TransactionTestCase) can inherit from. I
> have experimentally written a SimpleTestCase based class for my needs,
> but I haven't yet tested it against the Django suite.

Sounds reasonable to me; those non-db-related helpers shouldn't need to
be on TransactionTestCase.

Carl

Ramiro Morales

unread,
Mar 7, 2013, 6:40:42 PM3/7/13
to django-d...@googlegroups.com
On Thu, Mar 7, 2013 at 5:32 PM, zalew <zal...@gmail.com> wrote:
> fall back to SimpleTestCase (which
> TransactionTestCase inherits from), but this class doesn't contain useful
> test helpers, which aren't in any way related to db handling:
>
> * assertRedirects
> * assert(Not)Contains
> * assertFormError
> * assertTemplate(Not)Used
> * _urlconf_setup(teardown).
>
> Is there a reason why these functions were bound to a transaction handling
> test class instead of SimpleTestCase?
>
> My proposal is to move them out either to SimpleTestCase, or a separate
> class other tests (including TransactionTestCase) can inherit from. I have
> experimentally written a SimpleTestCase based class for my needs, but I
> haven't yet tested it against the Django suite.
>
> What do you think? If you agree and/or have some ideas, I will submit an
> issue and work on a patch proposal.

We inserted [1]SimpleTestCase in the hierarchy relatively [2]recently
(Django 1.4) and moved some functionality to it from its subclasses.

But at that time I didn't even think about challenging the status quo and
move all the non-DB related like you've just done.

+1 to you proposal. Please open a ticket. This thread and the ticket should
give the topic the visibility it needs to raise alarms if there is any backward
compatibility involved.

Thanks!

1. https://docs.djangoproject.com/en/1.5/topics/testing/overview/#django.test.SimpleTestCase
2. https://docs.djangoproject.com/en/1.5/releases/1.4/#minor-features

--
Ramiro Morales
@ramiromorales

zalew

unread,
Mar 7, 2013, 7:22:04 PM3/7/13
to django-d...@googlegroups.com

+1 to you proposal. Please open a ticket.
Reply all
Reply to author
Forward
0 new messages