-
Notifications
You must be signed in to change notification settings - Fork 137
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
Circumvent freezegun in favor of a real clock where possible #228
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ deps = | |
djangocurr: django>=2.2.0 | ||
pytest: pytest | ||
lxml>=3.6.0 | ||
freezegun | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be the same as django tests, i.e. if freezegun is not available, don't run those tests. - see other comment. |
||
commands = | ||
coverage run --append setup.py test | ||
coverage report --omit='.tox/*' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
"""Timing function that will attempt to circumvent freezegun and other common | ||
techniques of mocking time in Python unit tests; will only succeed at this on | ||
Unix currently. Falls back to regular time.time(). | ||
""" | ||
|
||
import time | ||
|
||
def get_real_time_if_possible(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this snippet is better
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: naming with something shorter like |
||
if hasattr(time, 'clock_gettime'): | ||
try: | ||
return time.clock_gettime(time.CLOCK_REALTIME) | ||
except OSError: | ||
# would occur if time.CLOCK_REALTIME is not available, for example | ||
pass | ||
return time.time() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unittest-xml-reporting/tests/django_test.py
Lines 11 to 26 in 6556d19
please use same kind of approach to not run things that depend on freezegun if it is not available