This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Test test_property failed if run twice
Type: behavior Stage: resolved
Components: Tests Versions: Python 3.6, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Nan Wu, berker.peksag, martin.panter, python-dev, rhettinger, serhiy.storchaka
Priority: normal Keywords:

Created on 2015-11-27 21:45 by serhiy.storchaka, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
fix_test_property_doc_writable_patch Nan Wu, 2015-12-04 04:06 review
Messages (7)
msg255493 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-11-27 21:45
$ ./python -m test.regrtest test_property test_property
[1/2] test_property
[2/2] test_property
test test_property failed -- Traceback (most recent call last):
  File "/home/serhiy/py/cpython-debug/Lib/test/test_property.py", line 172, in test_property_decorator_doc_writable
    self.assertEqual(sub.__class__.spam.__doc__, 'Eggs')
AssertionError: 'Spam' != 'Eggs'
- Spam
+ Eggs


1 test OK.
1 test failed:
    test_property
msg255495 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-11-27 21:53
As result the test is failed in leaks searching mode.

$ ./python -m test.regrtest -uall -R 3:3 test_property
[1/1] test_property
beginning 6 repetitions
123456
test test_property failed -- Traceback (most recent call last):
  File "/home/serhiy/py/cpython-debug/Lib/test/test_property.py", line 172, in test_property_decorator_doc_writable
    self.assertEqual(sub.__class__.spam.__doc__, 'Eggs')
AssertionError: 'Spam' != 'Eggs'
- Spam
+ Eggs


1 test failed:
    test_property
msg255851 - (view) Author: Nan Wu (Nan Wu) * Date: 2015-12-04 04:06
Thanks for catching this failure. In the patch, property doc is restore after write operation.
msg255911 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-12-05 00:43
Maybe it would be even better to wrap this up using unittest.mock.patch.object(). That is an obscure function that is hard to learn from the documentation, but very useful for testing. There is also test.support.swap_attr(), which is easier to figure out. Something like:

with patch.object(sub.__class__.spam, '__doc__', 'Spam'):
    self.assertEqual(sub.__class__.spam.__doc__, 'Spam')
msg255931 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-12-05 08:02
Or move the definition of the class to testing method.
msg256238 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-12-11 21:48
New changeset cc1aa0e88626 by Berker Peksag in branch '3.5':
Issue #25755: Move PropertyWritableDoc into the test case
https://hg.python.org/cpython/rev/cc1aa0e88626

New changeset 8f52c9d72d9f by Berker Peksag in branch 'default':
Issue #25755: Move PropertyWritableDoc into the test case
https://hg.python.org/cpython/rev/8f52c9d72d9f
msg256239 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2015-12-11 21:50
Thanks for the patch, Nan. I've updated your patch to apply Serhiy's advice.
History
Date User Action Args
2022-04-11 14:58:24adminsetgithub: 69941
2015-12-11 21:50:20berker.peksagsetstatus: open -> closed
versions: + Python 3.5
messages: + msg256239

resolution: fixed
stage: patch review -> resolved
2015-12-11 21:48:46python-devsetnosy: + python-dev
messages: + msg256238
2015-12-05 08:02:12serhiy.storchakasetmessages: + msg255931
2015-12-05 00:43:05martin.pantersetnosy: + martin.panter

messages: + msg255911
stage: patch review
2015-12-04 04:06:41Nan Wusetfiles: + fix_test_property_doc_writable_patch
nosy: + Nan Wu
messages: + msg255851

2015-11-27 21:54:00serhiy.storchakasetnosy: + rhettinger, berker.peksag
messages: + msg255495
2015-11-27 21:45:16serhiy.storchakacreate