prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Snippet caching is not cleared between tests
  Currently if you run a test that saves data in the exports cache, the data is still there in the next test
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `pytest_pootle/fixtures/site.py`
  Content:
  ```
  1 # -*- coding: utf-8 -*-
  2 #
  3 # Copyright (C) Pootle contributors.
  4 #
  5 # This file is a part of the Pootle project. It is distributed under the GPL3
  6 # or later license. See the LICENSE file for a copy of the license and the
  7 # AUTHORS file for copyright and authorship information.
  8 
  9 import tempfile
  10 
  11 import pytest
  12 
  13 from pytest_pootle.env import PootleTestEnv
  14 
  15 
  16 @pytest.fixture(autouse=True, scope='session')
  17 def setup_db_if_needed(request):
  18     """Sets up the site DB only if tests requested to use the DB (autouse)."""
  19     is_db_marker_set = [
  20         item for item in request.node.items
  21         if item.get_marker('django_db')
  22     ]
  23     if is_db_marker_set:
  24         return request.getfuncargvalue('post_db_setup')
  25 
  26     return None
  27 
  28 
  29 @pytest.fixture(scope='session')
  30 def post_db_setup(translations_directory, _django_db_setup,
  31                   _django_cursor_wrapper, request):
  32     """Sets up the site DB for the test session."""
  33     with _django_cursor_wrapper:
  34         PootleTestEnv(request).setup()
  35 
  36 
  37 @pytest.fixture
  38 def no_projects():
  39     from pootle_project.models import Project
  40 
  41     Project.objects.all().delete()
  42 
  43 
  44 @pytest.fixture
  45 def no_permissions():
  46     from django.contrib.auth.models import Permission
  47 
  48     Permission.objects.all().delete()
  49 
  50 
  51 @pytest.fixture
  52 def no_permission_sets():
  53     from pootle_app.models import PermissionSet
  54 
  55     PermissionSet.objects.all().delete()
  56 
  57 
  58 @pytest.fixture
  59 def no_submissions():
  60     from pootle_statistics.models import Submission
  61 
  62     Submission.objects.all().delete()
  63 
  64 
  65 @pytest.fixture
  66 def no_users():
  67     from django.contrib.auth import get_user_model
  68 
  69     User = get_user_model()
  70     User.objects.all().delete()
  71 
  72 
  73 @pytest.fixture
  74 def no_extra_users():
  75     from django.contrib.auth import get_user_model
  76 
  77     User = get_user_model()
  78     User.objects.exclude(
  79         username__in=["system", "default", "nobody"]).delete()
  80 
  81 
  82 @pytest.fixture(autouse=True, scope="session")
  83 def translations_directory(request):
  84     """used by PootleEnv"""
  85     from django.conf import settings
  86     settings.POOTLE_TRANSLATION_DIRECTORY = tempfile.mkdtemp()
  87
  ```
  
  Path: `pytest_pootle/fixtures/revision.py`
  Content:
  ```
  1 #!/usr/bin/env python
  2 # -*- coding: utf-8 -*-
  3 #
  4 # Copyright (C) Pootle contributors.
  5 #
  6 # This file is a part of the Pootle project. It is distributed under the GPL3
  7 # or later license. See the LICENSE file for a copy of the license and the
  8 # AUTHORS file for copyright and authorship information.
  9 
  10 import pytest
  11 
  12 
  13 @pytest.fixture(autouse=True)
  14 def revision():
  15     """Sets up the revision counter for each test call."""
  16     from pootle.core.models import Revision
  17 
  18     Revision.initialize()
  19
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/pytest_pootle/fixtures/revision.py b/pytest_pootle/fixtures/revision.py
  --- a/pytest_pootle/fixtures/revision.py
  +++ b/pytest_pootle/fixtures/revision.py
  @@ -11,8 +11,12 @@
   
   
   @pytest.fixture(autouse=True)
  -def revision():
  -    """Sets up the revision counter for each test call."""
  +def revision(request, clear_cache):
  +    """Sets up the cached revision counter for each test call."""
       from pootle.core.models import Revision
  +    from pootle_store.models import Unit
   
  -    Revision.initialize()
  +    if request.node.get_marker("django_db"):
  +        Revision.set(Unit.max_revision())
  +    else:
  +        Revision.initialize()
  diff --git a/pytest_pootle/fixtures/site.py b/pytest_pootle/fixtures/site.py
  --- a/pytest_pootle/fixtures/site.py
  +++ b/pytest_pootle/fixtures/site.py
  @@ -84,3 +84,13 @@
       """used by PootleEnv"""
       from django.conf import settings
       settings.POOTLE_TRANSLATION_DIRECTORY = tempfile.mkdtemp()
  +
  +
  +@pytest.fixture(autouse=True)
  +def clear_cache(request):
  +    """Currently tests only use one cache so this clears all"""
  +
  +    from django_redis import get_redis_connection
  +
  +    r_con = get_redis_connection('default')
  +    r_con.flushdb()
  
verification_info: {"golden_diff": "diff --git a/pytest_pootle/fixtures/revision.py b/pytest_pootle/fixtures/revision.py\n--- a/pytest_pootle/fixtures/revision.py\n+++ b/pytest_pootle/fixtures/revision.py\n@@ -11,8 +11,12 @@\n \n \n @pytest.fixture(autouse=True)\n-def revision():\n-    \"\"\"Sets up the revision counter for each test call.\"\"\"\n+def revision(request, clear_cache):\n+    \"\"\"Sets up the cached revision counter for each test call.\"\"\"\n     from pootle.core.models import Revision\n+    from pootle_store.models import Unit\n \n-    Revision.initialize()\n+    if request.node.get_marker(\"django_db\"):\n+        Revision.set(Unit.max_revision())\n+    else:\n+        Revision.initialize()\ndiff --git a/pytest_pootle/fixtures/site.py b/pytest_pootle/fixtures/site.py\n--- a/pytest_pootle/fixtures/site.py\n+++ b/pytest_pootle/fixtures/site.py\n@@ -84,3 +84,13 @@\n     \"\"\"used by PootleEnv\"\"\"\n     from django.conf import settings\n     settings.POOTLE_TRANSLATION_DIRECTORY = tempfile.mkdtemp()\n+\n+\n+@pytest.fixture(autouse=True)\n+def clear_cache(request):\n+    \"\"\"Currently tests only use one cache so this clears all\"\"\"\n+\n+    from django_redis import get_redis_connection\n+\n+    r_con = get_redis_connection('default')\n+    r_con.flushdb()\n", "issue": "Snippet caching is not cleared between tests\nCurrently if you run a test that saves data in the exports cache, the data is still there in the next test\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n#\n# Copyright (C) Pootle contributors.\n#\n# This file is a part of the Pootle project. It is distributed under the GPL3\n# or later license. See the LICENSE file for a copy of the license and the\n# AUTHORS file for copyright and authorship information.\n\nimport tempfile\n\nimport pytest\n\nfrom pytest_pootle.env import PootleTestEnv\n\n\n@pytest.fixture(autouse=True, scope='session')\ndef setup_db_if_needed(request):\n    \"\"\"Sets up the site DB only if tests requested to use the DB (autouse).\"\"\"\n    is_db_marker_set = [\n        item for item in request.node.items\n        if item.get_marker('django_db')\n    ]\n    if is_db_marker_set:\n        return request.getfuncargvalue('post_db_setup')\n\n    return None\n\n\n@pytest.fixture(scope='session')\ndef post_db_setup(translations_directory, _django_db_setup,\n                  _django_cursor_wrapper, request):\n    \"\"\"Sets up the site DB for the test session.\"\"\"\n    with _django_cursor_wrapper:\n        PootleTestEnv(request).setup()\n\n\n@pytest.fixture\ndef no_projects():\n    from pootle_project.models import Project\n\n    Project.objects.all().delete()\n\n\n@pytest.fixture\ndef no_permissions():\n    from django.contrib.auth.models import Permission\n\n    Permission.objects.all().delete()\n\n\n@pytest.fixture\ndef no_permission_sets():\n    from pootle_app.models import PermissionSet\n\n    PermissionSet.objects.all().delete()\n\n\n@pytest.fixture\ndef no_submissions():\n    from pootle_statistics.models import Submission\n\n    Submission.objects.all().delete()\n\n\n@pytest.fixture\ndef no_users():\n    from django.contrib.auth import get_user_model\n\n    User = get_user_model()\n    User.objects.all().delete()\n\n\n@pytest.fixture\ndef no_extra_users():\n    from django.contrib.auth import get_user_model\n\n    User = get_user_model()\n    User.objects.exclude(\n        username__in=[\"system\", \"default\", \"nobody\"]).delete()\n\n\n@pytest.fixture(autouse=True, scope=\"session\")\ndef translations_directory(request):\n    \"\"\"used by PootleEnv\"\"\"\n    from django.conf import settings\n    settings.POOTLE_TRANSLATION_DIRECTORY = tempfile.mkdtemp()\n", "path": "pytest_pootle/fixtures/site.py"}, {"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n#\n# Copyright (C) Pootle contributors.\n#\n# This file is a part of the Pootle project. It is distributed under the GPL3\n# or later license. See the LICENSE file for a copy of the license and the\n# AUTHORS file for copyright and authorship information.\n\nimport pytest\n\n\n@pytest.fixture(autouse=True)\ndef revision():\n    \"\"\"Sets up the revision counter for each test call.\"\"\"\n    from pootle.core.models import Revision\n\n    Revision.initialize()\n", "path": "pytest_pootle/fixtures/revision.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n#\n# Copyright (C) Pootle contributors.\n#\n# This file is a part of the Pootle project. It is distributed under the GPL3\n# or later license. See the LICENSE file for a copy of the license and the\n# AUTHORS file for copyright and authorship information.\n\nimport tempfile\n\nimport pytest\n\nfrom pytest_pootle.env import PootleTestEnv\n\n\n@pytest.fixture(autouse=True, scope='session')\ndef setup_db_if_needed(request):\n    \"\"\"Sets up the site DB only if tests requested to use the DB (autouse).\"\"\"\n    is_db_marker_set = [\n        item for item in request.node.items\n        if item.get_marker('django_db')\n    ]\n    if is_db_marker_set:\n        return request.getfuncargvalue('post_db_setup')\n\n    return None\n\n\n@pytest.fixture(scope='session')\ndef post_db_setup(translations_directory, _django_db_setup,\n                  _django_cursor_wrapper, request):\n    \"\"\"Sets up the site DB for the test session.\"\"\"\n    with _django_cursor_wrapper:\n        PootleTestEnv(request).setup()\n\n\n@pytest.fixture\ndef no_projects():\n    from pootle_project.models import Project\n\n    Project.objects.all().delete()\n\n\n@pytest.fixture\ndef no_permissions():\n    from django.contrib.auth.models import Permission\n\n    Permission.objects.all().delete()\n\n\n@pytest.fixture\ndef no_permission_sets():\n    from pootle_app.models import PermissionSet\n\n    PermissionSet.objects.all().delete()\n\n\n@pytest.fixture\ndef no_submissions():\n    from pootle_statistics.models import Submission\n\n    Submission.objects.all().delete()\n\n\n@pytest.fixture\ndef no_users():\n    from django.contrib.auth import get_user_model\n\n    User = get_user_model()\n    User.objects.all().delete()\n\n\n@pytest.fixture\ndef no_extra_users():\n    from django.contrib.auth import get_user_model\n\n    User = get_user_model()\n    User.objects.exclude(\n        username__in=[\"system\", \"default\", \"nobody\"]).delete()\n\n\n@pytest.fixture(autouse=True, scope=\"session\")\ndef translations_directory(request):\n    \"\"\"used by PootleEnv\"\"\"\n    from django.conf import settings\n    settings.POOTLE_TRANSLATION_DIRECTORY = tempfile.mkdtemp()\n\n\n@pytest.fixture(autouse=True)\ndef clear_cache(request):\n    \"\"\"Currently tests only use one cache so this clears all\"\"\"\n\n    from django_redis import get_redis_connection\n\n    r_con = get_redis_connection('default')\n    r_con.flushdb()\n", "path": "pytest_pootle/fixtures/site.py"}, {"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n#\n# Copyright (C) Pootle contributors.\n#\n# This file is a part of the Pootle project. It is distributed under the GPL3\n# or later license. See the LICENSE file for a copy of the license and the\n# AUTHORS file for copyright and authorship information.\n\nimport pytest\n\n\n@pytest.fixture(autouse=True)\ndef revision(request, clear_cache):\n    \"\"\"Sets up the cached revision counter for each test call.\"\"\"\n    from pootle.core.models import Revision\n    from pootle_store.models import Unit\n\n    if request.node.get_marker(\"django_db\"):\n        Revision.set(Unit.max_revision())\n    else:\n        Revision.initialize()\n", "path": "pytest_pootle/fixtures/revision.py"}]}