Skip to content

[tests] Fix import-time SQLite creation and add tmp_path fixtures for test isolation#174

Open
lin121291 wants to merge 1 commit into52North:mainfrom
lin121291:test/refactor-database-fixtures
Open

[tests] Fix import-time SQLite creation and add tmp_path fixtures for test isolation#174
lin121291 wants to merge 1 commit into52North:mainfrom
lin121291:test/refactor-database-fixtures

Conversation

@lin121291
Copy link
Copy Markdown

@lin121291 lin121291 commented Mar 14, 2026

Changes:

Further Details:

Summary:

Problem:
The original test files created SQLite database files in the class body, which executes at import time rather than test runtime. This caused several issues:

  1. File pollution: Database files created in working directory without cleanup
  2. Naming conflicts: Both test files used the same filename gdfDB.sqlite
  3. Poor test isolation: Global engine variables shared across tests
  4. Anti-pattern: I/O operations executing at import time in class body

Solution:
Replace ad-hoc database creation with proper pytest fixtures:

  • Database files now created in temporary directories via tmp_path_factory
  • Automatic cleanup after test completion
  • Proper dependency injection instead of global variables
  • Improved test isolation with separate databases per test class

Behaviour before: Tests created gdfDB.sqlite in working directory at import time, file remained after tests
Behaviour after: Tests create databases in temporary directories during test execution, automatic cleanup

Dependencies:

No new dependencies added.

PR Checklist:

In the context of this PR, I:

  • have filled the 52North Contributor License Agreement and am waiting for feedback
  • provide unit tests embedded in the WRT test framework (WeatherRoutingTool/tests) that allow the simple testing of the new/modified functionalities. All (previous and new) unit tests execute without new error messages.
  • ensure that the code formatter runs without errors/warnings
  • ensure that my changes follow the WRT's guidelines for contributing at the time of the contribution

Move database creation from class body to pytest fixtures.
Eliminates file pollution and improves test isolation.
@lin121291 lin121291 force-pushed the test/refactor-database-fixtures branch from 23f2c81 to b1513f4 Compare March 14, 2026 05:07
@lin121291 lin121291 changed the title [tests] Introduce pytest fixtures for database management [tests] Fix import-time SQLite creation and add tmp_path fixtures for test isolation Mar 14, 2026
@kdemmich
Copy link
Copy Markdown
Collaborator

Hi @lin121291, thank you for your PR. We appreciate the time and effort that was put into it. Please be aware that we require to follow 52 North's CLA guidelines for all PRs and, in particular, fill the 52°North Contributor License Agreement. As long as this has not been filled, I can not assign you to any issues or merge any PRs. Please don't hesitate to contact me in case of related questions.

@kdemmich kdemmich added the question Further information is requested label Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

question Further information is requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants