#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)
Change History (17)
by , 14 years ago
Attachment: | 15561-1.diff added |
---|
by , 14 years ago
Attachment: | 15561-i18n-tests.diff added |
---|
As an example, apply new test utils to i18n tests
comment:1 by , 14 years ago
milestone: | → 1.4 |
---|---|
Patch needs improvement: | set |
Triage Stage: | Unreviewed → Accepted |
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 , 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 , 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 , 14 years ago
Needs documentation: | set |
---|---|
Owner: | changed from | to
comment:5 by , 14 years ago
Type: | → New feature |
---|
comment:6 by , 14 years ago
Severity: | → Normal |
---|
comment:7 by , 14 years ago
Easy pickings: | unset |
---|
A context manager version of this functionality was added in r16165.
comment:8 by , 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 , 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 , 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.
Add settings manipulation functions in django test utilities