You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/utilities/parameters.md
+75-3
Original file line number
Diff line number
Diff line change
@@ -518,9 +518,9 @@ The **`config`** and **`boto3_session`** parameters enable you to pass in a cust
518
518
519
519
## Testing your code
520
520
521
-
For unit testing your applications, you can mock the calls to the parameters utility to avoid calling AWS APIs. This
522
-
can be achieved in a number of ways - in this example, we use the [pytest monkeypatch fixture](https://docs.pytest.org/en/latest/how-to/monkeypatch.html)
523
-
to patch the `parameters.get_parameter` method:
521
+
### Mocking parameter values
522
+
523
+
For unit testing your applications, you can mock the calls to the parameters utility to avoid calling AWS APIs. This can be achieved in a number of ways - in this example, we use the [pytest monkeypatch fixture](https://docs.pytest.org/en/latest/how-to/monkeypatch.html)to patch the `parameters.get_parameter` method:
524
524
525
525
=== "tests.py"
526
526
```python
@@ -588,3 +588,75 @@ object named `get_parameter_mock`.
588
588
assert return_val.get('message') == 'mock_value'
589
589
590
590
```
591
+
592
+
593
+
### Clearing cache
594
+
595
+
Parameters utility caches all parameter values for performance and cost reasons. However, this can have unintended interference in tests using the same parameter name.
596
+
597
+
Within your tests, you can use `clear_cache` method available in [every provider](#built-in-provider-class). When using multiple providers or higher level functions like `get_parameter`, use `clear_caches` standalone function to clear cache globally.
598
+
599
+
600
+
=== "clear_cache method"
601
+
```python hl_lines="9"
602
+
import pytest
603
+
604
+
from src import app
605
+
606
+
607
+
@pytest.fixture(scope="function", autouse=True)
608
+
def clear_parameters_cache():
609
+
yield
610
+
app.ssm_provider.clear_cache() # This will clear SSMProvider cache
0 commit comments