Skip to content

Conversation

@misrasaurabh1
Copy link
Contributor

@misrasaurabh1 misrasaurabh1 commented Oct 29, 2025

User description

prevents bugs like https://github.com/codeflash-ai/inference/pull/590/files


PR Type

Enhancement, Tests


Description

  • Use non-round fixed timestamp for determinism

  • Align fixed datetime to new value

  • Update tests to match new constants

  • Maintain deterministic UUID and random behavior


Diagram Walkthrough

flowchart LR
  plugin["pytest_plugin: fixed time constants"] -- "updated to non-rounded values" --> tests["tests: expected values updated"]
  plugin -- "consistent datetime, uuid, random" --> tests
Loading

File Walkthrough

Relevant files
Enhancement
pytest_plugin.py
Switch to non-rounded deterministic time values                   

codeflash/verification/pytest_plugin.py

  • Replace fixed_timestamp with 1761717605.108106
  • Update fixed_datetime to 2021-01-01 02:05:10+00:00
  • Keep deterministic UUID and perf counter behavior
+2/-2     
Tests
test_pytest_plugin_deterministic_patches.py
Align tests with new deterministic time constants               

tests/test_pytest_plugin_deterministic_patches.py

  • Update test fixed_timestamp to 1761717605.108106
  • Update expected datetimes to 2021-01-01 02:05:10+00:00
  • Adjust assertions relying on previous rounded time
+6/-6     

Signed-off-by: Saurabh Misra <[email protected]>
Signed-off-by: Saurabh Misra <[email protected]>
@github-actions
Copy link

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Consistency

Verify all patched time-related functions (time.time, datetime.now, datetime.utcnow, time.perf_counter) consistently reflect the new non-rounded timestamp and datetime, including fractional seconds behavior in perf_counter and any code assuming midnight alignment.

# Fixed deterministic values
fixed_timestamp = 1761717605.108106
fixed_datetime = datetime.datetime(2021, 1, 1, 2, 5, 10, tzinfo=datetime.timezone.utc)
fixed_uuid = uuid.UUID("12345678-1234-5678-9abc-123456789012")

# Counter for perf_counter to maintain relative timing
_perf_counter_start = fixed_timestamp
Fragile Constants

Tests duplicate fixed constants inline; consider centralizing via import from the plugin or a shared test constant to avoid future drift if the fixed time changes again.

# Create deterministic implementations (matching pytest_plugin.py)
fixed_timestamp = 1761717605.108106
fixed_datetime = datetime.datetime(2021, 1, 1, 2, 5, 10, tzinfo=datetime.timezone.utc)
fixed_uuid = uuid.UUID("12345678-1234-5678-9abc-123456789012")

# Counter for perf_counter
perf_counter_start = fixed_timestamp

@github-actions
Copy link

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Synchronize fixed time sources

Align fixed_datetime to represent the same instant as fixed_timestamp. Currently
they point to different moments, which can cause inconsistent mocks across
time.time() and datetime.now(). Either compute fixed_datetime from fixed_timestamp
or adjust the timestamp to match the stated datetime.

codeflash/verification/pytest_plugin.py [101-102]

-fixed_timestamp = 1761717605.108106
+fixed_timestamp = 1609553110.0  # 2021-01-01 02:05:10 UTC
 fixed_datetime = datetime.datetime(2021, 1, 1, 2, 5, 10, tzinfo=datetime.timezone.utc)
Suggestion importance[1-10]: 8

__

Why: The suggestion correctly identifies that fixed_timestamp and fixed_datetime represent different instants, which can cause inconsistent deterministic behavior across mocks. Aligning them is important for correctness; the improved code consistently matches the datetime, making the change high-impact and accurate.

Medium
General
Honor provided timezone in test

Ensure timezone handling remains consistent when a tz is passed to the mock. If
mock_now(tz) is expected to honor the provided tz, construct expected_with_tz with
the same tz instead of always using UTC, preventing false positives or negatives.

tests/test_pytest_plugin_deterministic_patches.py [381]

-expected_with_tz = datetime.datetime(2021, 1, 1, 2, 5, 10, tzinfo=datetime.timezone.utc)
+expected_with_tz = datetime.datetime(2021, 1, 1, 2, 5, 10, tzinfo=utc_tz)
Suggestion importance[1-10]: 7

__

Why: The test currently hardcodes UTC even when a tz argument is passed; using the provided utc_tz makes the expectation align with function semantics and avoids brittle tests. It's a valid improvement to test correctness, though not critical to functionality.

Medium

@KRRT7 KRRT7 merged commit ab4b2b0 into main Oct 29, 2025
22 of 26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants