Skip to content

Commit 3fa18cc

Browse files
Refactoring tests
1 parent fdf1b09 commit 3fa18cc

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

aws_lambda_powertools/utilities/data_masking/base.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
DataMaskingUnsupportedTypeError,
2020
)
2121
from aws_lambda_powertools.utilities.data_masking.provider import BaseProvider
22+
from aws_lambda_powertools.warnings import PowertoolsUserWarning
2223

2324
if TYPE_CHECKING:
2425
from numbers import Number
@@ -102,6 +103,7 @@ def erase(
102103
self,
103104
data: Any,
104105
fields: list[str] | None = None,
106+
*,
105107
dynamic_mask: bool | None = None,
106108
custom_mask: str | None = None,
107109
regex_pattern: str | None = None,
@@ -311,11 +313,11 @@ def _apply_masking_rules(self, data: dict, masking_rules: dict) -> dict:
311313
match.full_path.update(result, masked_value)
312314

313315
except Exception as e:
314-
warnings.warn(f"Error masking value for path {path}: {str(e)}", stacklevel=2)
316+
warnings.warn(f"Error masking value for path {path}: {str(e)}", category=PowertoolsUserWarning, stacklevel=2)
315317
continue
316318

317319
except Exception as e:
318-
warnings.warn(f"Error processing path {path}: {str(e)}", stacklevel=2)
320+
warnings.warn(f"Error processing path {path}: {str(e)}", category=PowertoolsUserWarning, stacklevel=2)
319321
continue
320322

321323
return result

tests/functional/data_masking/required_dependencies/test_erase_data_masking.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
DataMaskingFieldNotFoundError,
99
DataMaskingUnsupportedTypeError,
1010
)
11+
from aws_lambda_powertools.warnings import PowertoolsUserWarning
1112

1213

1314
@pytest.fixture
@@ -304,7 +305,7 @@ def erase(self, value, **kwargs):
304305
data_masker.provider = MockProvider()
305306

306307
# WHEN erase is called
307-
with pytest.warns(UserWarning, match="Error masking value for path value: Mock error"):
308+
with pytest.warns(expected_warning=PowertoolsUserWarning, match="Error masking value for path value: Mock error"):
308309
masked_data = data_masker.erase(data, masking_rules={"value": {"rule": "value"}})
309310

310311
# THEN the original data should remain unchanged
@@ -422,5 +423,5 @@ def test_erase_dictionary_with_masking_rules_wrong_field(data_masker):
422423

423424
# WHEN erase is called with wrong masking rules
424425
# We must have a warning
425-
with pytest.warns(UserWarning, match="Error processing path*"):
426+
with pytest.warns(expected_warning=PowertoolsUserWarning, match="Error processing path*"):
426427
data_masker.erase(data, masking_rules=masking_rules)

0 commit comments

Comments
 (0)