Ticket #11505: patch.diff

File patch.diff, 1.9 KB (added by andrewfong, 6 years ago)

Adds cache flushing after every testcase + a simple regression test

  • django/test/testcases.py

     
    214214              ROOT_URLCONF with it.
    215215            * Clearing the mail test outbox.
    216216        """
     217        self._flush_cache()
    217218        self._fixture_setup()
    218219        self._urlconf_setup()
    219220        mail.outbox = []
     221   
     222    def _flush_cache(self):
     223        from django.core.cache import cache
     224        cache.flush()
    220225
    221226    def _fixture_setup(self):
    222227        call_command('flush', verbosity=0, interactive=False)
  • tests/regressiontests/testcase/__init__.py

     
     1
  • tests/regressiontests/testcase/tests.py

     
     1from django.test import TestCase
     2
     3class TestCacheFlushed(TestCase):
     4    # The cache should be flushed in between test cases
     5    # Test that the cache setting in one test is not
     6    # affecting the other
     7
     8    def setUp(self):
     9        self.key = 'hello'
     10        from django.core.cache import cache
     11        self.cache = cache
     12
     13    def test_a(self):
     14        self.assertEqual(self.cache.get(self.key), None)
     15        self.cache.set(self.key, 'world')
     16
     17    def test_b(self):
     18        self.assertEqual(self.cache.get(self.key), None)
     19        self.cache.set(self.key, 'world')
     20
  • tests/regressiontests/testcase/models.py

     
     1
Back to Top