Opened 14 years ago

Closed 14 years ago

Last modified 13 years ago

#15561 closed New feature (fixed)

Factorize settings manipulation in tests

Reported by: Claude Paroz Owned by: Łukasz Rekucki
Component: Testing framework Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

I found a rather good implementation of django settings altering in the mail regression tests, and found that it could be reused in a lot of other Django tests, and of course in all Django applications.

So I'm proposing to take the alter_django_settings/restore_django_settings functions and the with_django_settings decorator out from regressiontests/mail/tests.py and offer these in general Django test utilities.

Attachments (5)

15561-1.diff (3.2 KB ) - added by Claude Paroz 14 years ago.
Add settings manipulation functions in django test utilities
15561-i18n-tests.diff (11.3 KB ) - added by Claude Paroz 14 years ago.
As an example, apply new test utils to i18n tests
15561.2.diff (12.2 KB ) - added by Jannis Leidel 14 years ago.
with_settings decorator/context manager combo
15561.3.diff (12.3 KB ) - added by Jannis Leidel 14 years ago.
Renamed to override_settings
15561.4.diff (14.9 KB ) - added by Jannis Leidel 14 years ago.
Extended docs.

Download all attachments as: .zip

Change History (17)

by Claude Paroz, 14 years ago

Attachment: 15561-1.diff added

Add settings manipulation functions in django test utilities

by Claude Paroz, 14 years ago

Attachment: 15561-i18n-tests.diff added

As an example, apply new test utils to i18n tests

comment:1 by Russell Keith-Magee, 14 years ago

milestone: 1.4
Patch needs improvement: set
Triage Stage: UnreviewedAccepted

Agreed, this is a good idea, both for Django's own test suite, and as a tool that could be used by the broader community.

One thing that might be worth considering -- there are certain settings that, if changed, cause values to be cached. For example, when you set L10N and access date/number formatting operations, the formats are cached. It would be good to include the cache flushing operations as an automatic part of this settings decorator.

It would also be good if the decorator worked as a class decorator, as well as a method decorator.

comment:2 by Łukasz Rekucki, 14 years ago

Related discussion on django-developers: http://groups.google.com/group/django-developers/browse_thread/thread/65aabb45687e572e. This includes discussion about how to flush settings. Also related is ticket #14628.

comment:3 by Claude Paroz, 14 years ago

I'm probably not the best person to improve the patch as I'm not expert in decorators. Hopefully someone more skilled than me could help here. I'm available though to browse current tests to migrate to the new functions.

comment:4 by Łukasz Rekucki, 14 years ago

Needs documentation: set
Owner: changed from nobody to Łukasz Rekucki

comment:5 by Luke Plant, 14 years ago

Type: New feature

comment:6 by Luke Plant, 14 years ago

Severity: Normal

comment:7 by Ramiro Morales, 14 years ago

Easy pickings: unset

A context manager version of this functionality was added in r16165.

comment:8 by Jannis Leidel, 14 years ago

Oops, didn't know this ticket existed. I suppose we could additionally add a decorator to do the same as the context manager.

comment:9 by Claude Paroz, 14 years ago

I hesitated to close this one when I saw the work of jezdez. But after reading the code, I think that there still might be use cases for decorators.

comment:10 by Jannis Leidel, 14 years ago

Needs tests: set

Agreed, but the patch needs to use the same technique the TestCase.settings CM uses (using UserSettingsHandler) since that'll make sure that the previous settings instance is reset correctly.

by Jannis Leidel, 14 years ago

Attachment: 15561.2.diff added

with_settings decorator/context manager combo

by Jannis Leidel, 14 years ago

Attachment: 15561.3.diff added

Renamed to override_settings

by Jannis Leidel, 14 years ago

Attachment: 15561.4.diff added

Extended docs.

comment:11 by Jannis Leidel, 14 years ago

Resolution: fixed
Status: newclosed

In [16237]:

Fixed #15561 -- Extended test setting override code added in r16165 with a decorator and a signal for setting changes.

comment:12 by Jacob, 13 years ago

milestone: 1.4

Milestone 1.4 deleted

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