Fix flaky EngineProcessor time filter tests#8058
Merged
pavoljuhas merged 7 commits intoquantumlib:mainfrom Apr 27, 2026
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8058 +/- ##
==========================================
- Coverage 99.63% 99.63% -0.01%
==========================================
Files 1110 1110
Lines 99794 99954 +160
==========================================
+ Hits 99433 99591 +158
- Misses 361 363 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
dstrain115
reviewed
Apr 23, 2026
pavoljuhas
requested changes
Apr 23, 2026
Collaborator
pavoljuhas
left a comment
There was a problem hiding this comment.
I think we can fix this without changing engine_processor.py.
Following the idea in #7851 (comment), here is a datetime.datetime subclass that can be added to engine_processor_test.py
class _FrozenDateTime(datetime.datetime):
_stock_datetime = datetime.datetime
@classmethod
@functools.cache
def now(cls, tz=None):
return cls._stock_datetime.now(tz)The affected test functions can be then decorated with
@mock.patch('datetime.datetime', _FrozenDateTime)
which would replacedatetime.datetime for their execution.
senahazir
commented
Apr 27, 2026
Contributor
Author
senahazir
left a comment
There was a problem hiding this comment.
Updated the PR with the requested changes.
It is sufficient to apply for them the mocking of datetime.datetime with _FrozenDateTime. It is also unnecessary to reset the _FrozenDateTime.now, although it is good to know such option exists.
(This should fail pytest)
(This should pass tests)
pavoljuhas
approved these changes
Apr 27, 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.
This fix addresses the flaky tests in engine_processor_test.py as explained in #7851.
The tests are fixed by mocking the
datetime.datetimeclass with a subclass_FrozenDateTimeto makedatetime.datetime.now()return a constant.I reproduced the issue by adding
import time; time.sleep(1)to bothtest_get_schedule_time_filter_behaviorandtest_list_reservations_time_filter_behaviorand confirmed that the fix works for both cases (though I removed the sleeps for this pr).Fixes #7851