Skip to content

Commit 5cf6517

Browse files
author
Tom McCarthy
committed
chore: Improve file handling in example tests
1 parent ab51ba1 commit 5cf6517

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

docs/core/event_handler/appsync.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -781,13 +781,15 @@ Here's an example of how you can test your synchronous resolvers:
781781

782782
```python
783783
import pytest
784+
from pathlib import Path
785+
784786
from src.index import app # import the instance of AppSyncResolver from your code
785787

786788
def test_direct_resolver():
787789
# Load mock event from a file
788-
json_file = "appSyncDirectResolver.json"
789-
fh = open(file)
790-
mock_event = json.load(fh)
790+
json_file_path = Path("appSyncDirectResolver.json")
791+
with open(json_file_path) as json_file:
792+
mock_event = json.load(json_file)
791793

792794
# Call the implicit handler
793795
result = app(mock_event, {})
@@ -822,14 +824,16 @@ And an example for testing asynchronous resolvers. Note that this requires the `
822824

823825
```python
824826
import pytest
827+
from pathlib import Path
828+
825829
from src.index import app # import the instance of AppSyncResolver from your code
826830

827831
@pytest.mark.asyncio
828832
async def test_direct_resolver():
829833
# Load mock event from a file
830-
json_file = "appSyncDirectResolver.json"
831-
fh = open(file)
832-
mock_event = json.load(fh)
834+
json_file_path = Path("appSyncDirectResolver.json")
835+
with open(json_file_path) as json_file:
836+
mock_event = json.load(json_file)
833837

834838
# Call the implicit handler
835839
result = await app(mock_event, {})

0 commit comments

Comments
 (0)