Tests#
Base Class for Test Cases#
Base test utilities for Sentry SDK integration testing.
This module provides a common base class that automatically mocks sentry_sdk.init for all Sentry-related test cases, ensuring tests run in isolation without making actual network calls to Sentry.
- Classes:
BaseSentryTestCases: Base test class with automatic Sentry SDK mocking.
Example
Create a test class that inherits from BaseSentryTestCases:
from core_sentry.tests.base import BaseSentryTestCases
class MyTests(BaseSentryTestCases):
def test_sentry_integration(self):
# sentry_sdk.init is automatically mocked
# Access the mock via self.sentry_mock
pass
Key Components:
1. Automatic Sentry Mocking: - Creates a patcher for sentry_sdk.init - Stores the mock object for test assertions
2. Class-level Setup/Teardown: - setUpClass() starts the patcher and stores the mock - tearDownClass() stops the patcher
- Benefits:
Prevents actual Sentry initialization during tests
Consistent mocking across all test classes that inherit from it
Clean test isolation - each test class gets fresh mocking
Reduces boilerplate - no need to manually patch sentry_sdk.init in each test
Provides access to the mock object for assertions
- class core_sentry.tests.base.BaseSentryTestCases(methodName='runTest')[source]#
Bases:
TestCaseBase class for Test Cases related to Sentry integration
- sentry_patcher = <unittest.mock._patch object>#
- sentry_mock = None#
- classmethod setUpClass() None[source]#
Hook method for setting up class fixture before running tests in the class.
- classmethod tearDownClass() None[source]#
Hook method for deconstructing the class fixture after running all tests in the class.
- _classSetupFailed = False#
- _class_cleanups = []#