-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
gh-143959 make test_sys import _datetime inside the test #144003
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
base: main
Are you sure you want to change the base?
Conversation
vstinner
left a comment
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.
LGTM
Lib/test/test_sys.py
Outdated
| self.assertEqual(sys.getsizeof(True, -1), size('') + self.longdigit) | ||
|
|
||
| def test_objecttypes(self): | ||
| import _datetime |
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.
I suggest to import it just before it is used, like collections.
And since it is optional, skip the corresponding test if the import fails.
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.
Thanks! Fixed it
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.
And since it is optional, skip the corresponding test if the import fails.
_datetime is now a built-in module, it's not really optional.
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.
Isn't it just an implementation detail? It was made builtin to solve a particular technical issue which can be solved in other way.
| check(x, size('5Pi')) | ||
| # PyCapsule | ||
| import _datetime | ||
| check(_datetime.datetime_CAPI, size('6P')) |
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.
As @serhiy-storchaka requested, this line should only be run if _datetime is available. Something like:
try:
import _datetime
except ImportError:
pass
else:
check(_datetime.datetime_CAPI, size('6P'))
The
_datetimedependency oftest_sysis only required for@cpython_onlydecorated test.