test: run session teardown in bookmark file-input restore test (#2482) - #2490
Open
drewe7192 wants to merge 1 commit into
Open
test: run session teardown in bookmark file-input restore test (#2482)#2490drewe7192 wants to merge 1 commit into
drewe7192 wants to merge 1 commit into
Conversation
In `test_file_restore_handler_registers_snapshot_preprocess`, the `shiny.file` bookmark restore handler creates a `tempfile.TemporaryDirectory` and registers its cleanup via `session.on_ended()`. Because the test never explicitly completed the session lifecycle, the cleanup callback never fired, leaving the directory to be reclaimed at GC time and emitting a `ResourceWarning`. Convert the test to async and invoke `await session._run_session_ended_tasks()` in a `finally` block so the directory is cleaned up deterministically upon test completion. Fixes posit-dev#2482
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #2482
Description
In
tests/pytest/test_test_mode.py,test_file_restore_handler_registers_snapshot_preprocessexercises theshiny.filebookmark restore handler. This handler instantiates atempfile.TemporaryDirectoryand registers cleanup viasession.on_ended(lambda: tempdir_root.cleanup()).Because the test previously exited without ending the session lifecycle, the cleanup callback never fired during the test execution. The directory was left to Python's cyclic garbage collector, intermittently emitting an unraisable
ResourceWarning: Implicitly cleaning up <TemporaryDirectory ...>during test teardown.Solution
test_file_restore_handler_registers_snapshot_preprocesswith@pytest.mark.asyncioand converted it to anasync def.try...finallyblock that callsawait session._run_session_ended_tasks(), ensuring the registeredon_endedcleanup hook executes deterministically at test completion.Testing
pytest tests/pytest/test_test_mode.py -k test_file_restore_handler_registers_snapshot_preprocesspasses cleanly without unhandled warnings.