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

bpo-30822: Fix testing of datetime module. #2530

Merged
merged 6 commits into from
Jul 2, 2017

Conversation

musically-ut
Copy link
Contributor

@musically-ut musically-ut commented Jul 1, 2017

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 (in datetimetester.py) depends on the following condition (or the negation thereof):

if '_Fast' in str(self):
    # ...

The cls.__name__ is modified in the test_datetime.py to be:

    cls.__name__ = name + suffix   # suffix in ['_Fast', '_Pure']

However, str(self) to derives the class name from cls.__qualname__ and not cls.__name__. This meant that _Fast was never in str(self) and, hence, some of the tests were being unnecessarily skipped (notably test_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 variable test_classes inside a loop. That is fixed in a separate commit.

#1493 depends on this PR.

  • Backport to 3.6
  • Backport to 3.5

[1]: Example on core-mentorship archives (accessible only to members).

@mention-bot
Copy link

@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.

@@ -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':
Copy link
Member

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__?

Copy link
Contributor Author

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.

Copy link
Member

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__.

@@ -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
Copy link
Member

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.

@@ -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
Copy link
Member

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__.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@@ -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':
Copy link
Member

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__.

if '_Fast' not in str(self):
return
if '_Pure' in self.__class__.__name__:
return self.skipTest('Only run for Fast C implementation')
Copy link
Member

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.

Copy link
Contributor Author

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.

@serhiy-storchaka serhiy-storchaka merged commit 98b6bc3 into python:master Jul 2, 2017
@serhiy-storchaka serhiy-storchaka added needs backport to 3.5 tests Tests in the Lib/test dir labels Jul 2, 2017
musically-ut added a commit to musically-ut/cpython that referenced this pull request Jul 3, 2017
Only C implementation was tested..
(cherry picked from commit 98b6bc3)
@bedevere-bot
Copy link

GH-2550 is a backport of this pull request to the 3.5 branch.

musically-ut added a commit to musically-ut/cpython that referenced this pull request Jul 3, 2017
Only C implementation was tested.
(cherry picked from commit 98b6bc3)
@bedevere-bot
Copy link

GH-2551 is a backport of this pull request to the 3.6 branch.

vstinner added a commit that referenced this pull request Jul 5, 2017
vstinner added a commit that referenced this pull request Jul 5, 2017
* 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.
musically-ut added a commit to musically-ut/cpython that referenced this pull request Jul 20, 2017
vstinner pushed a commit that referenced this pull request Jul 21, 2017
musically-ut added a commit to musically-ut/cpython that referenced this pull request Jul 22, 2017
…honGH-2783)

Only C implementation was tested..
(cherry picked from commit 287c559)
musically-ut added a commit to musically-ut/cpython that referenced this pull request Jul 22, 2017
…honGH-2783)

Only C implementation was tested.
(cherry picked from commit 287c559)
musically-ut added a commit to musically-ut/cpython that referenced this pull request Jul 22, 2017
…honGH-2783)

Only C implementation was tested..
(cherry picked from commit 287c559)
vstinner pushed a commit that referenced this pull request Jul 26, 2017
…2816)

* [3.6] bpo-30822: Fix testing of datetime module. (GH-2530) (GH-2783)

Only C implementation was tested.
(cherry picked from commit 287c559)

* [3.6] bpo-30822: Fix testing of datetime module. (GH-2530) (GH-2783)

Only C implementation was tested..
(cherry picked from commit 287c559)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants