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 test_time being always 0.0 #292

Merged
merged 2 commits into from
Apr 12, 2024
Merged

Conversation

eltoder
Copy link
Contributor

@eltoder eltoder commented Apr 11, 2024

The bug was introduced in commit 651ab46 when setting start_time = 0.0 was added to ProtoTestResult.reinitialize().

The bug was introduced in commit 651ab46
when setting start_time = 0.0 was added to ProtoTestResult.reinitialize().
@eltoder
Copy link
Contributor Author

eltoder commented Apr 11, 2024

It's probably a good idea to do a thorough testing of everything given the amount of recent changes.

@sodul sodul self-assigned this Apr 11, 2024
@coveralls
Copy link

coveralls commented Apr 11, 2024

Coverage Status

coverage: 0.0%. remained the same
when pulling 2606d63 on eltoder:feature/fix-test-times
into 9e9e5cf on CleanCut:main.

Comment on lines 111 to 115
ptr = ProtoTestResult()
test = proto_test(MagicMock())
ptr.startTest(test)
ptr.stopTest(test)
self.assertGreater(float(ptr.test_time), 0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

For readability it is better to use plain words:

Suggested change
ptr = ProtoTestResult()
test = proto_test(MagicMock())
ptr.startTest(test)
ptr.stopTest(test)
self.assertGreater(float(ptr.test_time), 0)
result = ProtoTestResult()
test = proto_test(MagicMock())
result.startTest(test)
result.stopTest(test)
self.assertGreater(float(result.test_time), 0)

That said I have a bit of concern about this because time is not mocked and on a future very fast machine it would not be impossible for the time to be recorded as a true zero.

We could add https://pypi.org/project/freezegun/ in our requirements-dev.txt file and use it to mock the time to ensure that we have predictable behavior.

Copy link
Contributor Author

@eltoder eltoder Apr 11, 2024

Choose a reason for hiding this comment

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

It's better to be consistent with other tests. This is the naming and the structure used in all other tests in TestProtoTestResult.

I don't think we need to worry about time being zero. Even calling time.time() in a tight loop does not produce the same number. If it does become a problem, we can simply add a small sleep in the test. freezegun sets time to a constant, which will result in test_time being zero. If we need to mock, we can directly mock time.time() to an iterable, so it returns different values on subsequent calls.

@CleanCut what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added mocking for time.time() and a more precise assert.

@sodul
Copy link
Collaborator

sodul commented Apr 11, 2024

Thanks for the PR and sorry for introducing this bug. I'm not sure why I did not notice it.

@eltoder
Copy link
Contributor Author

eltoder commented Apr 11, 2024

Btw, looks like the coverage number in the CI is wrong ^^

@sodul
Copy link
Collaborator

sodul commented Apr 12, 2024

For the lack of coverage we are tracking this in #289 but I have not had time to look into it since it seems to be limited to green's GH action. Local coverage numbers are fine.

Copy link
Collaborator

@sodul sodul left a comment

Choose a reason for hiding this comment

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

LGTM

@sodul sodul merged commit d706f98 into CleanCut:main Apr 12, 2024
24 checks passed
@eltoder eltoder deleted the feature/fix-test-times branch April 12, 2024 00:52
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.

3 participants