fix: change db initialization in config_template tests #295
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.
This PR was motivated by encountering these errors for test_config_template.py:
I'm not 100% sure why these tests started failing locally, why they still pass on GH actions, and why this fix now allows them to pass locally. After much back-and-forth with Claude, I still do not have a satisfactory answer, but I have decided to move on for now to get back to more pressing work. The best explanation I can offer is that somehow (but only locally and starting only recently), the test was referring to two different engines that each had their own database.
Old test flow:
- This engine has its own in-memory database
- Test creates tables and data in Engine 1's database
- This is a completely separate engine instance
- For sqlite:///:memory:, this means a separate in-memory database
- Engine 2's database is empty - no tables, no data
New test code:
db_module._get_engine(template_settings.db_url) # Gets/creates the cached engine
db_module.Base.metadata.create_all(engine) # Creates tables in the cached engine
app = create_app(template_settings) # Uses the same cached engine by calling _get_engine internally