Skip to content

test: check the finalizer error inside FinalizerError, not its message - #42

Merged
lesnik512 merged 1 commit into
mainfrom
test/finalizer-error-4.1
Oct 10, 2026
Merged

lesnik512 merged 1 commit into
mainfrom
test/finalizer-error-4.1

Conversation

@lesnik512

Copy link
Copy Markdown
Member

Two tests fail against modern-di 4.1.0:

  • tests/test_aio.py::test_wrap_unary_aio_resets_context_var_when_close_raises
  • tests/test_inject.py::test_wrap_unary_sync_resets_context_var_when_close_raises

Both used pytest.raises(RuntimeError, match="boom"). "boom" is the message of the finalizer's own exception, and on 4.0.0 FinalizerError's message included it. In 4.1.0 (modern-python/modern-di#631) the message is a summary, Container.close_sync() found 1 finalizer error(s): RuntimeError (1), so the match fails. The integration code is unaffected.

The tests now catch FinalizerError and check that its only exception is RuntimeError("boom"). That checks the same thing without depending on the message text. They still go on to check that the context variable was reset, which is what they are for.

Tests

  • The two tests failed on 4.1.0 before this change.
  • With the change, all 30 tests pass on 4.1.0 and on 4.0.0, so the modern-di>=4,<5 range stays covered.
  • just lint and just test-ci (100% coverage) pass.

@lesnik512
lesnik512 merged commit ef65429 into main Oct 10, 2026
10 checks passed
@lesnik512
lesnik512 deleted the test/finalizer-error-4.1 branch October 10, 2026 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant