fix: prevent resource leaks in tests when failures occur #291
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #290
Problem
Some tests were creating and deleting Notion resources manually. When tests failed, the cleanup code never ran, leaving resources behind in Notion.
Solution
Refactored tests to use pytest fixtures with
yieldfor guaranteed cleanup. The cleanup code afteryieldalways runs, even if the test fails.Changes
Added 3 new fixtures in
conftest.py:multiple_test_pages- Creates 5 test pages for pagination testsasync_multiple_test_pages- Async version of aboveasync_test_data_source- Creates database and data source for testingUpdated 5 problematic tests to use fixtures instead of inline resource management:
test_iterate_paginated_apitest_async_iterate_paginated_apitest_async_iterate_data_source_templatestest_async_collect_data_source_templatesThese are the ones I noticed , happy to update more if the maintainers know of others.