From c0cb1d63686544f60f2f44f7de48d6987cdf2072 Mon Sep 17 00:00:00 2001 From: Maxim Zhiltsov Date: Thu, 3 Oct 2024 19:09:49 +0300 Subject: [PATCH] Add kvrocks cleanup after class in rest api tests --- cvat/apps/engine/frame_provider.py | 4 ++-- tests/python/rest_api/test_tasks.py | 9 ++++++++- tests/python/shared/fixtures/init.py | 11 +++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/cvat/apps/engine/frame_provider.py b/cvat/apps/engine/frame_provider.py index 4341500baeb..f397f0d568b 100644 --- a/cvat/apps/engine/frame_provider.py +++ b/cvat/apps/engine/frame_provider.py @@ -490,8 +490,8 @@ def get_frame_index(self, frame_number: int) -> Optional[int]: abs_frame_number = self._get_abs_frame_number(self._db_segment.task.data, frame_number) frame_index = bisect(segment_frames, abs_frame_number) - 1 if not ( - 0 <= frame_index < len(segment_frames) and - segment_frames[frame_index] == abs_frame_number + 0 <= frame_index < len(segment_frames) + and segment_frames[frame_index] == abs_frame_number ): return None diff --git a/tests/python/rest_api/test_tasks.py b/tests/python/rest_api/test_tasks.py index 4a88aef4de8..d64f2b06eef 100644 --- a/tests/python/rest_api/test_tasks.py +++ b/tests/python/rest_api/test_tasks.py @@ -737,6 +737,7 @@ def interpolate(frame): @pytest.mark.usefixtures("restore_db_per_class") @pytest.mark.usefixtures("restore_redis_inmem_per_function") +@pytest.mark.usefixtures("restore_redis_ondisk_after_class") class TestGetTaskDataset: @staticmethod @@ -987,6 +988,7 @@ def test_uses_subset_name( @pytest.mark.usefixtures("restore_db_per_function") @pytest.mark.usefixtures("restore_cvat_data_per_function") @pytest.mark.usefixtures("restore_redis_ondisk_per_function") +@pytest.mark.usefixtures("restore_redis_ondisk_after_class") class TestPostTaskData: _USERNAME = "admin1" @@ -2593,8 +2595,9 @@ def read_frame(self, i: int) -> Image.Image: @pytest.mark.usefixtures("restore_db_per_class") -@pytest.mark.usefixtures("restore_redis_ondisk_per_class") @pytest.mark.usefixtures("restore_cvat_data_per_class") +@pytest.mark.usefixtures("restore_redis_ondisk_per_class") +@pytest.mark.usefixtures("restore_redis_ondisk_after_class") class TestTaskData: _USERNAME = "admin1" @@ -3571,6 +3574,8 @@ def test_work_with_task_containing_non_stable_cloud_storage_files( @pytest.mark.usefixtures("restore_redis_inmem_per_function") +@pytest.mark.usefixtures("restore_redis_ondisk_per_class") +@pytest.mark.usefixtures("restore_redis_ondisk_after_class") class TestTaskBackups: @pytest.fixture(autouse=True) def setup( @@ -4379,6 +4384,8 @@ def test_task_unassigned_cannot_see_task_preview( self._test_assigned_users_cannot_see_task_preview(tasks, users, is_task_staff) +@pytest.mark.usefixtures("restore_redis_ondisk_per_class") +@pytest.mark.usefixtures("restore_redis_ondisk_after_class") class TestUnequalJobs: @pytest.fixture(autouse=True) def setup(self, restore_db_per_function, tmp_path: Path, admin_user: str): diff --git a/tests/python/shared/fixtures/init.py b/tests/python/shared/fixtures/init.py index 98388c0d0cd..84e18110b0d 100644 --- a/tests/python/shared/fixtures/init.py +++ b/tests/python/shared/fixtures/init.py @@ -634,3 +634,14 @@ def restore_redis_ondisk_per_class(request): docker_restore_redis_ondisk() else: kube_restore_redis_ondisk() + + +@pytest.fixture(scope="class") +def restore_redis_ondisk_after_class(request): + yield + + platform = request.config.getoption("--platform") + if platform == "local": + docker_restore_redis_ondisk() + else: + kube_restore_redis_ondisk()