refactor(tests): use db_session_with_containers in test_storage_key_loader#35766
Merged
asukaminato0721 merged 3 commits intoMay 2, 2026
Conversation
…oader (langgenius#32860) Convert TestStorageKeyLoader from unittest.TestCase to a pytest class that receives the db_session_with_containers fixture as a parameter, removing the direct db.session() call pattern flagged in langgenius#32860. Changes: - Remove unittest.TestCase inheritance and setUp/tearDown - Add db_session_with_containers as a parameter on every test method - Convert per-test DB setup helpers to @staticmethod helpers that accept a session argument, keeping helpers co-located with the tests - Preserve all existing test scenarios (local file, remote URL, tool file, mixed methods, empty list, tenant isolation, session isolation, etc.) - Add flask_req_ctx_with_containers via @pytest.mark.usefixtures Part of langgenius#32860
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-05-02 15:48:22.807276324 +0000
+++ /tmp/pyrefly_pr.txt 2026-05-02 15:48:15.079202106 +0000
@@ -5528,10 +5528,6 @@
--> tests/unit_tests/factories/test_build_from_mapping.py:132:12
ERROR Object of class `NoneType` has no attribute `storage_key` [missing-attribute]
--> tests/unit_tests/factories/test_build_from_mapping.py:164:12
-ERROR `in` is not supported between `Literal['file']` and `None` [not-iterable]
- --> tests/unit_tests/factories/test_file_factory.py:282:16
-ERROR `in` is not supported between `Literal['.txt']` and `None` [not-iterable]
- --> tests/unit_tests/factories/test_file_factory.py:283:16
ERROR Argument `datetime` is not assignable to parameter `created_at` with type `Decimal | bool | bytes | float | int | str | None` in function `fields.file_fields.FileWithSignedUrl.__init__` [bad-argument-type]
--> tests/unit_tests/fields/test_file_fields.py:55:20
ERROR `dict[str, str | None]` is not assignable to TypedDict key `site` with type `list[dict[str, Any]] | list[dict[str, str]] | str` [bad-typed-dict-key]
|
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors the containerized integration tests for StorageKeyLoader to use pytest-style tests that receive db_session_with_containers, eliminating the direct db.session() pattern and aligning with the container test fixture lifecycle.
Changes:
- Convert
TestStorageKeyLoaderfromunittest.TestCase(setUp/tearDown) to a plain pytest test class. - Thread
db_session_with_containers: Sessionthrough all test methods and update helper builders to accept an explicitSession. - Minor formatting-only whitespace adjustments in a stress-test TypedDict helper file.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
api/tests/test_containers_integration_tests/factories/test_storage_key_loader.py |
Reworks tests to pytest + db_session_with_containers, refactoring per-test setup into session-accepting helper methods. |
scripts/stress-test/common/config_helper.py |
Adds blank lines inside several TypedDict definitions (formatting-only). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
asukaminato0721
approved these changes
May 2, 2026
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.
…oader (#32860)
Convert TestStorageKeyLoader from unittest.TestCase to a pytest class that receives the db_session_with_containers fixture as a parameter, removing the direct db.session() call pattern flagged in #32860.
Changes:
Part of #32860
Description
Important
Fixes #<issue number>.Summary
Part of #32860 — converts
TestStorageKeyLoaderfrom aunittest.TestCasesubclass that callsdb.session()directly to a pytest class that receives thedb_session_with_containersfixture as a parameter.Changes
class TestStorageKeyLoader(unittest.TestCase)class TestStorageKeyLoader(plain pytest class)setUp(self): self.session = db.session()db_session_with_containers: SessiontearDown(self): self.session.close()self._create_*methods that usedself.session@staticmethodhelpers that takesessionas a parameterWhy this matters
db.session()bypasses the transaction rollback managed bydb_session_with_containers, which can leave test data in the database between tests and cause flakiness. The fixture ensures each test runs in an isolated transaction that is rolled back after completion.All existing test scenarios preserved
test_load_storage_keys_local_filetest_load_storage_keys_remote_urltest_load_storage_keys_tool_filetest_load_storage_keys_mixed_methodstest_load_storage_keys_empty_listtest_load_storage_keys_ignores_legacy_file_tenant_idtest_load_storage_keys_missing_file_idtest_load_storage_keys_nonexistent_upload_file_recordstest_load_storage_keys_nonexistent_tool_file_recordstest_load_storage_keys_invalid_uuidtest_load_storage_keys_batch_efficiencytest_load_storage_keys_tenant_isolationtest_load_storage_keys_mixed_tenant_batchtest_load_storage_keys_duplicate_file_idstest_load_storage_keys_session_isolationChecklist
db.session()calls remain in the test file.