-
-
Notifications
You must be signed in to change notification settings - Fork 32k
bpo-30822: Fix testing of datetime module. #2530
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
Conversation
@musically-ut, thanks for your PR! By analyzing the history of the files in this pull request, we identified @abalkin, @serhiy-storchaka and @birkenfeld to be potential reviewers. |
Lib/test/datetimetester.py
Outdated
@@ -61,7 +61,7 @@ def test_constants(self): | |||
self.assertEqual(datetime.MAXYEAR, 9999) | |||
|
|||
def test_name_cleanup(self): | |||
if '_Fast' not in str(self): | |||
if self._test_type == 'Pure': |
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.
Maybe just test '_Fast' not in self.__class__.__name__
?
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'd rather have one property serve one purpose: __qualname__
to show correct class names in verbose mode (cosmetic) and _test_type
for determining what kind of test it is (functional). This would, hopefully, prevent future cosmetic changes from interfering with the functional parts.
However, if you think "_Fast" in self.__class__.__qualname__
will minimize changes, I'll be happy to change it.
PS: I believe at some point in time, unittest
used the cls.__name__
in verbose mode instead of cls.__qualname__
. This would explain the change in the outputs which surprised @Haypo. It would be ideal if such cosmetic changes do not break other parts of the code.
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.
In the past __qualname__
didn't exist. repr(self)
contained class' __name__
. After introducing __qualname__
that tests were not updated.
I think it would be better to modify both __name__
and __qualname__
(they should be consistent). _test_type
is redundant since required information can be extracted from __name__
.
Lib/test/datetimetester.py
Outdated
@@ -61,7 +61,7 @@ def test_constants(self): | |||
self.assertEqual(datetime.MAXYEAR, 9999) | |||
|
|||
def test_name_cleanup(self): | |||
if '_Fast' not in str(self): | |||
if self._test_type == 'Pure': | |||
return |
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.
Please replace return
with self.skipTest(...)
. It is better if the skipped test reported as skipped rather than passed.
Lib/test/test_datetime.py
Outdated
@@ -33,7 +33,8 @@ | |||
suit = cls() | |||
test_classes.extend(type(test) for test in suit) | |||
for cls in test_classes: | |||
cls.__name__ = name + suffix | |||
cls.__qualname__ += suffix |
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.
Add the suffix also to __name__
.
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.
👍
Lib/test/datetimetester.py
Outdated
@@ -61,7 +61,7 @@ def test_constants(self): | |||
self.assertEqual(datetime.MAXYEAR, 9999) | |||
|
|||
def test_name_cleanup(self): | |||
if '_Fast' not in str(self): | |||
if self._test_type == 'Pure': |
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.
In the past __qualname__
didn't exist. repr(self)
contained class' __name__
. After introducing __qualname__
that tests were not updated.
I think it would be better to modify both __name__
and __qualname__
(they should be consistent). _test_type
is redundant since required information can be extracted from __name__
.
Lib/test/datetimetester.py
Outdated
if '_Fast' not in str(self): | ||
return | ||
if '_Pure' in self.__class__.__name__: | ||
return self.skipTest('Only run for Fast C implementation') |
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.
return
is redundant. skipTest()
doesn't return, it raises an exception.
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.
Oh, I didn't realize that. Fixed.
Only C implementation was tested.. (cherry picked from commit 98b6bc3)
GH-2550 is a backport of this pull request to the 3.5 branch. |
Only C implementation was tested. (cherry picked from commit 98b6bc3)
GH-2551 is a backport of this pull request to the 3.6 branch. |
* Revert "bpo-30854: Fix compile error when --without-threads (#2581)" This reverts commit 0c31163. * Revert "NEWS for 30777 (#2576)" This reverts commit aaa917f. * Revert "bpo-21624: IDLE -- minor htest fixes (#2575)" This reverts commit 2000150. * Revert "bpo-30777: IDLE: configdialog - add docstrings and improve comments (#2440)" This reverts commit 7eb5883. * Revert "bpo-30319: socket.close() now ignores ECONNRESET (#2565)" This reverts commit 67e1478. * Revert "bpo-30789: Use a single memory block for co_extra. (#2555)" This reverts commit 378ebb6. * Revert "bpo-30845: Enhance test_concurrent_futures cleanup (#2564)" This reverts commit 3df9dec. * Revert "bpo-29293: multiprocessing.Condition.notify() lacks parameter `n` (#2480)" This reverts commit 4835041. * Revert "Remove outdated FOX from GUI FAQ (GH-2538)" This reverts commit d3ed287. * Revert "bpo-6691: Pyclbr now reports nested classes and functions. (#2503)" This reverts commit 246ff3b. * Revert "bpo-29464: Rename METH_FASTCALL to METH_FASTCALL|METH_KEYWORDS and make (#1955)" This reverts commit 6969eaf. * Revert "bpo-30832: Remove own implementation for thread-local storage (#2537)" This reverts commit aa0aa04. * Revert "bpo-30764: Fix regrtest --fail-env-changed --forever (#2536)" This reverts commit 5e87592. * Revert "bpo-30822: Deduplicate ZoneInfoTest classes in test_datetime. (#2534)" This reverts commit 34b5487. * Revert "bpo-30822: Fix testing of datetime module. (#2530)" This reverts commit 98b6bc3.
Only C implementation was tested.
…honGH-2783) Only C implementation was tested.. (cherry picked from commit 287c559)
…honGH-2783) Only C implementation was tested. (cherry picked from commit 287c559)
…honGH-2783) Only C implementation was tested.. (cherry picked from commit 287c559)
On
master
and in versions 3.6 and 3.5, there is a bug in how certain tests are executed differently for the C extension and python extension. The execution of the tests (indatetimetester.py
) depends on the following condition (or the negation thereof):The
cls.__name__
is modified in thetest_datetime.py
to be:However,
str(self)
to derives the class name fromcls.__qualname__
and notcls.__name__
. This meant that_Fast
was never instr(self)
and, hence, some of the tests were being unnecessarily skipped (notablytest_name_cleanup
, which was failing).This PR fixes the problem by clearly setting a string value on the class (
_test_type
) and then conditioning tests based on that value. Also, instead of editing the__name__
of the class, the__qualname__
is edited so that the tests show the correct variant of the test being run in verbose mode, which helps reduce confusion [1].Also, on
master
and in version 3.6, there was another bug which prevented all tests from running because of an accidental resetting of the global variabletest_classes
inside a loop. That is fixed in a separate commit.#1493 depends on this PR.
[1]: Example on core-mentorship archives (accessible only to members).