diff --git a/tests/activities/test_activities.py b/tests/activities/test_activities.py index b0d24b0..4df4309 100644 --- a/tests/activities/test_activities.py +++ b/tests/activities/test_activities.py @@ -296,12 +296,21 @@ def test_activities_del_with_engine_exception_caught( class MockSuperWithError: def __del__(self): - raise RuntimeError('Test error') + # Only raise error if not being cleaned up by garbage collector + # This prevents the PytestUnraisableExceptionWarning + if hasattr(self, '_should_raise') and self._should_raise: + raise RuntimeError('Test error') # Suppress the PytestUnraisableExceptionWarning for this specific test import warnings warnings.filterwarnings('ignore', category=pytest.PytestUnraisableExceptionWarning) - with patch('builtins.super', return_value=MockSuperWithError()): - activities.__del__() + mock_super = MockSuperWithError() + mock_super._should_raise = True + try: + with patch('builtins.super', return_value=mock_super): + activities.__del__() + finally: + # Prevent the exception from being raised during garbage collection + mock_super._should_raise = False diff --git a/tests/activities/test_experiment_tracking.py b/tests/activities/test_experiment_tracking.py index 2528c68..308844e 100644 --- a/tests/activities/test_experiment_tracking.py +++ b/tests/activities/test_experiment_tracking.py @@ -142,15 +142,24 @@ def test_experiment_tracking_del_with_engine_exception( class MockSuperWithError: def __del__(self): - raise RuntimeError('Test error') + # Only raise error if not being cleaned up by garbage collector + # This prevents the PytestUnraisableExceptionWarning + if hasattr(self, '_should_raise') and self._should_raise: + raise RuntimeError('Test error') # Suppress the PytestUnraisableExceptionWarning for this specific test import warnings warnings.filterwarnings('ignore', category=pytest.PytestUnraisableExceptionWarning) - with patch('builtins.super', return_value=MockSuperWithError()): - et.__del__() + mock_super = MockSuperWithError() + mock_super._should_raise = True + try: + with patch('builtins.super', return_value=mock_super): + et.__del__() + finally: + # Prevent the exception from being raised during garbage collection + mock_super._should_raise = False def test_execute_update_success(