Skip to content

Fix timing dependent test_run_path_creation.py#12885

Merged
jonathan-eq merged 1 commit intoequinor:mainfrom
jonathan-eq:fix-flaky-test-91
Feb 19, 2026
Merged

Fix timing dependent test_run_path_creation.py#12885
jonathan-eq merged 1 commit intoequinor:mainfrom
jonathan-eq:fix-flaky-test-91

Conversation

@jonathan-eq
Copy link
Copy Markdown
Contributor

@jonathan-eq jonathan-eq commented Feb 16, 2026

Issue
Resolves timing issues

Approach
This commit fixes a potential timing dependent issue in test_that_pre_defines_are_substituted_templates[<DATE>] and test_that_the_data_file_keyword_also_has_similar_behavior_to_run_template[<DATE>]. These tests have been flaky at some point, and one of the potential sources of the flakiness was tests running while the date changes at midnight. This commit monkeypatches this to return 2026-01-01 at every time, making sure the timing issues will never occur.

(Screenshot of new behavior in GUI if applicable)

  • PR title captures the intent of the changes, and is fitting for release notes.
  • Added appropriate release note label
  • Commit history is consistent and clean, in line with the contribution guidelines.
  • Make sure unit tests pass locally after every commit (git rebase -i main --exec 'just rapid-tests')

When applicable

  • When there are user facing changes: Updated documentation
  • New behavior or changes to existing untested code: Ensured that unit tests are added (See Ground Rules).
  • Large PR: Prepare changes in small commits for more convenient review
  • Bug fix: Add regression test for the bug
  • Bug fix: Add backport label to latest release (format: 'backport release-branch-name')

@jonathan-eq jonathan-eq added the maintenance Not a bug now but could be one day, repaying technical debt label Feb 16, 2026
@jonathan-eq jonathan-eq self-assigned this Feb 16, 2026
@jonathan-eq jonathan-eq requested a review from Copilot February 16, 2026 12:51
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses flakiness in run-path creation unit tests by making <DATE> substitution deterministic, avoiding failures when tests span a midnight boundary.

Changes:

  • Replace runtime-derived <DATE> expectations with a fixed EXPECTED_DATE.
  • Monkeypatch the config parser’s datetime.date.today() used for default pre-defines so <DATE> is stable during the tests.

Comment on lines +327 to +332
fixed_date = datetime.fromisoformat(EXPECTED_DATE).date()
monkeypatch.setattr(
lark_parser.datetime,
"date",
MagicMock(today=MagicMock(return_value=fixed_date)),
)
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test replaces lark_parser.datetime.date with a nested MagicMock. It works for date.today(), but it’s brittle if lark_parser ever starts using datetime.date(...) or other date APIs during parsing. Consider patching lark_parser.datetime.date to a small datetime.date subclass that only overrides today() (preserving constructors/isoformat/etc.) to keep the patch safer and clearer.

Copilot uses AI. Check for mistakes.
Comment on lines +409 to +414
fixed_date = datetime.fromisoformat(EXPECTED_DATE).date()
monkeypatch.setattr(
lark_parser.datetime,
"date",
MagicMock(today=MagicMock(return_value=fixed_date)),
)
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fixed_date + monkeypatch.setattr(lark_parser.datetime, "date", …) block is duplicated in multiple tests in this file. To reduce repetition (and make future changes to the time-freezing approach less error-prone), consider extracting this into a small fixture/helper (e.g. freeze_lark_parser_date(monkeypatch)), then reuse it in both parametrized tests.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is just two tests, so the result will be about the same...

@jonathan-eq jonathan-eq moved this to Ready for Review in SCOUT Feb 16, 2026
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Feb 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.68%. Comparing base (4ee9441) to head (9fa9336).
⚠️ Report is 35 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #12885      +/-   ##
==========================================
+ Coverage   90.65%   90.68%   +0.02%     
==========================================
  Files         441      442       +1     
  Lines       30488    30496       +8     
==========================================
+ Hits        27640    27656      +16     
+ Misses       2848     2840       -8     
Flag Coverage Δ
cli-tests 37.22% <ø> (+0.05%) ⬆️
gui-tests 67.80% <ø> (+<0.01%) ⬆️
performance-and-unit-tests 77.15% <ø> (+0.03%) ⬆️
test 37.29% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jonathan-eq jonathan-eq moved this from Ready for Review to Fast Track in SCOUT Feb 16, 2026
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Feb 16, 2026

Merging this PR will not alter performance

✅ 34 untouched benchmarks


Comparing jonathan-eq:fix-flaky-test-91 (9fa9336) with main (822e61c)

Open in CodSpeed

).read_text() == "I WANT TO REPLACE:my_custom_variable"


EXPECTED_DATE = "2026-01-01"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you put this at the top of the file

This commit fixes a potential timing dependent issue in `test_that_pre_defines_are_substituted_templates[<DATE>]` and `test_that_the_data_file_keyword_also_has_similar_behavior_to_run_template[<DATE>]`. These tests have been flaky at some point, and one of the potential sources of the flakiness was tests running while the date changes at midnight. This commit monkeypatches this to return `2026-01-01` at every time, making sure the timing issues will never occur.
Copy link
Copy Markdown
Contributor

@frode-aarstad frode-aarstad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@github-project-automation github-project-automation Bot moved this from Fast Track to Reviewed in SCOUT Feb 18, 2026
@jonathan-eq jonathan-eq merged commit 42813ce into equinor:main Feb 19, 2026
35 checks passed
@jonathan-eq jonathan-eq deleted the fix-flaky-test-91 branch February 19, 2026 13:25
@github-project-automation github-project-automation Bot moved this from Reviewed to Done in SCOUT Feb 19, 2026
@scout-team-app
Copy link
Copy Markdown

Successfully created backport PR for version-20.0:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport version-20.0 maintenance Not a bug now but could be one day, repaying technical debt

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants