test: replace sleeps with freezegun time ticks in tests#957
Open
bndikt wants to merge 1 commit into
Open
Conversation
chrisburr
requested changes
Jun 23, 2026
| yield sandbox_metadata_db | ||
|
|
||
|
|
||
| @pytest.fixture |
Member
There was a problem hiding this comment.
As this is defined in two places it probably belongs in diracx-testing/src/diracx/testing/time.py
| db.engine.sync_engine, "connect", set_sqlite_pragma | ||
| ) | ||
| sqlalchemy.event.listen( | ||
| db.engine.sync_engine, "connect", mock_sqlite_time |
Member
There was a problem hiding this comment.
Similarly, this is now in three places, maybe it can be simplified with a helper:
# diracx-testing/src/diracx/testing/time.py
def install_sqlite_time_mock(engine) -> None:
"""Make SQLite's date/time functions follow frozen Python time on `engine`.
Registers `mock_sqlite_time` as a "connect" listener so every new DBAPI
connection gets the mocked DATETIME()/JULIANDAY()/... functions. Accepts a
sync Engine or an AsyncEngine.
"""
sync_engine = getattr(engine, "sync_engine", engine)
sqlalchemy.event.listen(sync_engine, "connect", mock_sqlite_time)
# utils.py:339 (create_db_schemas)
install_sqlite_time_mock(db.engine)
# test_sandbox_metadata.py:21 (sandbox_metadata_db fixture)
install_sqlite_time_mock(sandbox_metadata_db.engine)
# test_freeze_time.py:43
if with_mock:
install_sqlite_time_mock(engine)bb01425 to
0361f1e
Compare
Contributor
|
@chrisburr I noticed |
Contributor
|
test: centralize freezegun mock time helpers test: add time helper dependencies to testing package
0361f1e to
9515104
Compare
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.
Summary
freezeguntime ticksmock_sqlite_timesoDATETIME('now')follows frozen Python time