Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix time_ns() freeze rounding error #538

Merged
merged 2 commits into from Apr 23, 2024

Conversation

romuald
Copy link
Contributor

@romuald romuald commented Mar 20, 2024

The previous behavior of time_ns() mock did round the value of the frozen date to the seconds, excluding the microseconds if specified

This is mostly problematic when freeze_time() is used with the uuid1() method: multiple "frozen" dates within the same second would all generate the same uuid

The previous behavior of time_ns() mock did round the value of the
frozen date to the seconds, excluding the microseconds if specified

This is mostly problematic when freeze_time() is used with the uuid1()
method: multiple "frozen" dates within the same second would all
generate the same uuid
assert time.time() == expected_timestamp
assert time.time_ns() == expected_timestamp * 1e9
freezer.stop()
with freezer:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is totally unrelated: this test will crash pytest if the time_ns() function raises an error

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I understand your comment. On an error, wouldn't the __exit__ code run, and thus NOT cause any other test side effects? I'm failing to see an issue, could you please elaborate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The issue was present before the change. My comment should have said "did" crash and not "will" crash 😑

Copy link
Collaborator

@bblommers bblommers left a comment

Choose a reason for hiding this comment

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

Makes sense - thanks for fixing this @romuald!

@bblommers bblommers merged commit 45d9293 into spulec:master Apr 23, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants