SIENTIAPDE-1307: Fix PytestUnraisableExceptionWarning in activity and experiment tracking tests by controlling exception raising in __del__ mocks.
This commit is contained in:
@@ -296,12 +296,21 @@ def test_activities_del_with_engine_exception_caught(
|
|||||||
|
|
||||||
class MockSuperWithError:
|
class MockSuperWithError:
|
||||||
def __del__(self):
|
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
|
# Suppress the PytestUnraisableExceptionWarning for this specific test
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
warnings.filterwarnings('ignore', category=pytest.PytestUnraisableExceptionWarning)
|
warnings.filterwarnings('ignore', category=pytest.PytestUnraisableExceptionWarning)
|
||||||
|
|
||||||
with patch('builtins.super', return_value=MockSuperWithError()):
|
mock_super = MockSuperWithError()
|
||||||
activities.__del__()
|
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
|
||||||
|
|||||||
@@ -142,15 +142,24 @@ def test_experiment_tracking_del_with_engine_exception(
|
|||||||
|
|
||||||
class MockSuperWithError:
|
class MockSuperWithError:
|
||||||
def __del__(self):
|
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
|
# Suppress the PytestUnraisableExceptionWarning for this specific test
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
warnings.filterwarnings('ignore', category=pytest.PytestUnraisableExceptionWarning)
|
warnings.filterwarnings('ignore', category=pytest.PytestUnraisableExceptionWarning)
|
||||||
|
|
||||||
with patch('builtins.super', return_value=MockSuperWithError()):
|
mock_super = MockSuperWithError()
|
||||||
et.__del__()
|
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(
|
def test_execute_update_success(
|
||||||
|
|||||||
Reference in New Issue
Block a user