From 0bef78b0b4a296f5226072b6577e1d5c2f85db7a Mon Sep 17 00:00:00 2001 From: erinhmclark Date: Thu, 13 Mar 2025 15:23:35 +0000 Subject: [PATCH] Remove autouse property of mock_sleep. --- tests/conftest.py | 4 ++-- tests/enrichers/test_wayback_enricher.py | 6 ++++++ tests/enrichers/test_whisper_enricher.py | 6 ++++++ tests/extractors/test_instagram_tbot_extractor.py | 6 ++++++ tests/extractors/test_tiktok_tikwm_extractor.py | 10 +++------- tests/storages/test_gdrive_storage.py | 6 ++++++ 6 files changed, 29 insertions(+), 9 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 9754b91..379bfc2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -145,9 +145,9 @@ def sample_datetime(): return datetime(2023, 1, 1, 12, 0, tzinfo=timezone.utc) -@pytest.fixture(autouse=True) +@pytest.fixture def mock_sleep(mocker): - """Globally mock time.sleep to avoid delays.""" + """Mock time.sleep to avoid delays.""" return mocker.patch("time.sleep") diff --git a/tests/enrichers/test_wayback_enricher.py b/tests/enrichers/test_wayback_enricher.py index 796c805..113458b 100644 --- a/tests/enrichers/test_wayback_enricher.py +++ b/tests/enrichers/test_wayback_enricher.py @@ -5,6 +5,12 @@ from auto_archiver.modules.wayback_extractor_enricher import WaybackExtractorEnr from auto_archiver.core import Metadata +@pytest.fixture(autouse=True) +def mock_sleep(mocker): + """Mock time.sleep to avoid delays.""" + return mocker.patch("time.sleep") + + @pytest.fixture def mock_is_auth_wall(mocker): """Fixture to mock is_auth_wall behavior.""" diff --git a/tests/enrichers/test_whisper_enricher.py b/tests/enrichers/test_whisper_enricher.py index 0278e91..f669631 100644 --- a/tests/enrichers/test_whisper_enricher.py +++ b/tests/enrichers/test_whisper_enricher.py @@ -7,6 +7,12 @@ from auto_archiver.modules.whisper_enricher import WhisperEnricher TEST_S3_URL = "http://cdn.example.com/test.mp4" +@pytest.fixture(autouse=True) +def mock_sleep(mocker): + """Mock time.sleep to avoid delays.""" + return mocker.patch("time.sleep") + + @pytest.fixture def enricher(mocker): """Fixture with mocked S3 and API dependencies""" diff --git a/tests/extractors/test_instagram_tbot_extractor.py b/tests/extractors/test_instagram_tbot_extractor.py index 1b31d07..47a4bec 100644 --- a/tests/extractors/test_instagram_tbot_extractor.py +++ b/tests/extractors/test_instagram_tbot_extractor.py @@ -7,6 +7,12 @@ from auto_archiver.modules.instagram_tbot_extractor import InstagramTbotExtracto from tests.extractors.test_extractor_base import TestExtractorBase +@pytest.fixture(autouse=True) +def mock_sleep(mocker): + """Mock time.sleep to avoid delays.""" + return mocker.patch("time.sleep") + + @pytest.fixture def patch_extractor_methods(request, setup_module, mocker): mocker.patch.object(InstagramTbotExtractor, "_prepare_session_file", return_value=None) diff --git a/tests/extractors/test_tiktok_tikwm_extractor.py b/tests/extractors/test_tiktok_tikwm_extractor.py index cc50240..a21a17a 100644 --- a/tests/extractors/test_tiktok_tikwm_extractor.py +++ b/tests/extractors/test_tiktok_tikwm_extractor.py @@ -151,14 +151,10 @@ class TestTiktokTikwmExtractor(TestExtractorBase): assert result.get("timestamp") == datetime.fromtimestamp(1741122000, tz=timezone.utc) @pytest.mark.download - def test_download_sensitive_video(self, make_item, mock_sleep): - # sleep is needed because of the rate limit - mock_sleep.stop() - time.sleep(1.1) - mock_sleep.start() - + def test_download_sensitive_video(self, make_item): url = "https://www.tiktok.com/@ggs68taiwan.official/video/7441821351142362375" - + # Required for rate limiting + time.sleep(1.1) result = self.extractor.download(make_item(url)) assert result.is_success() assert len(result.media) == 2 diff --git a/tests/storages/test_gdrive_storage.py b/tests/storages/test_gdrive_storage.py index 501bd58..99df536 100644 --- a/tests/storages/test_gdrive_storage.py +++ b/tests/storages/test_gdrive_storage.py @@ -6,6 +6,12 @@ from auto_archiver.modules.gdrive_storage import GDriveStorage from tests.storages.test_storage_base import TestStorageBase +@pytest.fixture(autouse=True) +def mock_sleep(mocker): + """Mock time.sleep to avoid delays.""" + return mocker.patch("time.sleep") + + @pytest.fixture def gdrive_storage(setup_module, mocker) -> GDriveStorage: module_name: str = "gdrive_storage"