From d9778d90806f8b888db88adf9ef8b8ce7397fa5b Mon Sep 17 00:00:00 2001 From: Marcus Read Date: Fri, 18 Oct 2024 15:30:37 +0100 Subject: [PATCH] Fix flaky `test_daterange_duration_days_end_oolb_minute` Test was failing to raise expected error when intended start did not fall prior to the start limit as a result of the prior session closing early and the start evaluated by the drg falling on a non-trading minute after the close and then being reasonably advanced to the start limit, hence the expected `StartTooEarlyError` wasn't raised. Fixed by adding a day to the `days` in these circumstances only. --- tests/test_daterange.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/test_daterange.py b/tests/test_daterange.py index 35e300b..0659a29 100644 --- a/tests/test_daterange.py +++ b/tests/test_daterange.py @@ -2856,9 +2856,15 @@ def test_daterange_duration_days_end_oolb_minute( drg = self.get_drg(cal, pp, strict=False, **drg_kwargs) assert drg.daterange == ((limit, end), end) - drg = self.get_drg(cal, pp, strict=True, **drg_kwargs) start = end - (cal.day * pp["days"]) - start = start if cal.is_trading_minute(start) else cal.previous_close(start) + if not cal.is_trading_minute(start): + # take off an extra day, otherwise drg would reasonably advance start to + # the start limit and not trigger StartTooEarlyError + pp["days"] += 1 + start -= cal.day + start = start if cal.is_trading_minute(start) else cal.next_open(start) + + drg = self.get_drg(cal, pp, strict=True, **drg_kwargs) error_msg = re.escape( f"Prices unavailable as start evaluates to {helpers.fts(start)} which" " is earlier than the earliest minute for which price data is"