mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-10-04 02:04:06 +00:00
fix(tests): isolate mock class attrs leaking across tests (#12728)
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
|
||||
_MOCK_CLASSES = (
|
||||
mock.Mock,
|
||||
mock.MagicMock,
|
||||
mock.AsyncMock,
|
||||
mock.NonCallableMock,
|
||||
mock.NonCallableMagicMock,
|
||||
)
|
||||
_MOCK_CLASS_BASELINE = {cls: frozenset(vars(cls)) for cls in _MOCK_CLASSES}
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _reset_mock_class_attributes():
|
||||
"""Drop attributes a test sets on the mock classes themselves (`c = mock.MagicMock; c.provider = ...`), so they cannot leak into other tests' instances."""
|
||||
yield
|
||||
for cls, baseline in _MOCK_CLASS_BASELINE.items():
|
||||
for name in set(vars(cls)) - baseline:
|
||||
delattr(cls, name)
|
||||
Reference in New Issue
Block a user