Opened 13 years ago
Closed 13 years ago
#16401 closed New feature (duplicate)
Cache should be reset after each test without flushing
Reported by: | Jim Dalton | Owned by: | nobody |
---|---|---|---|
Component: | Testing framework | Version: | dev |
Severity: | Normal | Keywords: | cache |
Cc: | Jim Dalton | Triage Stage: | Unreviewed |
Has patch: | yes | Needs documentation: | yes |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
At present, when cache values are set during a test, those values carry over from test to test. This breaks proper test isolation and can making testing code that uses the cache cumbersome, since cache values have to be manually flushed.
Using cache.clear() would be on option to handle this, however this clears *all* the data in a cache, not just for your application. This could be considered impolite at best and dangerous at worst, so a proper solution would not resort to this measure.
Here are some guidelines/requirements for a solution:
- Any cache(s) used during a test run should ideally be restored to their original state when the test run is finished.
- Any cache values set during an individual test should be cleared when that test is finished.
Some discussion on the developers list here: https://groups.google.com/forum/#!topic/django-developers/zlaPsP13dUY
Attachments (1)
Change History (3)
comment:1 by , 13 years ago
Has patch: | set |
---|---|
Needs documentation: | set |
Patch needs improvement: | set |
by , 13 years ago
Attachment: | restore_cache_during_tests.diff added |
---|
comment:2 by , 13 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
I believe this is a duplicate of #11505.
Okay, I sat down to work on a patch. I think it worked out fine. The tests I added are pretty thorough and most everything seems to be working. A few notes:
That's all. It's actually pretty straightforward despite being a bit fiddly with the monkey patching, as that stuff usually is.
Any questions/comments/concerns let me know. Marking as patch needs improvement pending the fix for those two tests and needs documentation, assuming we might want to mention this in test docs.