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.
Created on 2014年08月06日 05:00 by martin.panter, last changed 2022年04月11日 14:58 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| myworkdoc.patch | evilzero, 2014年08月17日 20:00 | review | ||
| runtest.patch | martin.panter, 2014年12月05日 23:53 | review | ||
| runTest2-default.patch | martin.panter, 2014年12月06日 23:58 | review | ||
| runTest2-3.4.patch | martin.panter, 2014年12月06日 23:58 | review | ||
| Messages (17) | |||
|---|---|---|---|
| msg224907 - (view) | Author: Martin Panter (martin.panter) * (Python committer) | Date: 2014年08月06日 05:00 | |
The documentation for "unittest.TestCase" says "the standard implementation of the default 'methodName', runTest(), will run every method starting with 'test' as an individual test". However: >>> from unittest import * >>> class Test(TestCase): ... def test_method(self): pass ... >>> t = Test() >>> t.run() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python3.4/unittest/case.py", line 552, in run testMethod = getattr(self, self._testMethodName) AttributeError: 'Test' object has no attribute 'runTest' After further experimentation, I see that if my test method is called "runTest", it can be automatically discovered, but only if there are no other test- prefixed methods. Perhaps you could drop the end of the second paragraph for TestCase, so that it just reads: Each instance of TestCase will run a single base method: the method named "methodName". I think the details about the test- prefix and counting results are covered elsewhere, and in most uses you wouldn't instantiate a TestCase yourself, so changing the method name is irrelevant. Also, perhaps under "TestLoader.loadTestsFromTestCase" it should say: If no methods with the usual name prefix are found, but the "runTest" method is implemented, there will be a single test case using that method. |
|||
| msg225466 - (view) | Author: (evilzero) * | Date: 2014年08月17日 20:00 | |
Updated documentation following suggestion. |
|||
| msg230137 - (view) | Author: Martin Panter (martin.panter) * (Python committer) | Date: 2014年10月28日 10:52 | |
The patch seems reasonable to me |
|||
| msg230147 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2014年10月28日 13:16 | |
IMO hiding the existence of `runTest` would be best. It doesn't seem to make anything more flexible, and it complicates the documentation. |
|||
| msg230180 - (view) | Author: Martin Panter (martin.panter) * (Python committer) | Date: 2014年10月28日 21:57 | |
Do you mean pretending there is no default "methodName" value, or pretending that the runTest() method is not invoked by discovery? I would have to check, but I think I have relied on the runTest() method being discovered in the past, when I did not think a more original test method name was useful. Though I agree that it makes the behaviour more complicated for little extra flexibility. |
|||
| msg230181 - (view) | Author: Robert Collins (rbcollins) * (Python committer) | Date: 2014年10月28日 22:01 | |
runTest is part of the current API. I think if we're going to hide it we should do so as part of a deprecation path. (I'm +1 on hiding it). |
|||
| msg230182 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2014年10月28日 22:06 | |
Le 28/10/2014 23:01, Robert Collins a écrit : > > runTest is part of the current API. I think if we're going to hide > it we should do so as part of a deprecation path. (I'm +1 on hiding it). We don't need a deprecation path to remove something from the documentation, IMO. It wouldn't break any existing code, it would just reduce the cognitive load for newcomers. (and, while people may have chosen to use runTest, it doesn't mean they need it in any way) |
|||
| msg230188 - (view) | Author: Martin Panter (martin.panter) * (Python committer) | Date: 2014年10月28日 23:22 | |
Removing stuff from the documentation would make it hard to understand what existing code means that uses runTest(). Isn’t this a case where you would add a big red "Deprecated since version . . ." warning instead? Maybe a comprimise would be to "hide" its documentation away in a separate deprecated section or something. |
|||
| msg230190 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2014年10月29日 00:16 | |
Le 29/10/2014 00:22, Martin Panter a écrit : > > Martin Panter added the comment: > > Removing stuff from the documentation would make it hard to > understand what existing code means that uses runTest(). Isn’t this a case where you would add a big red "Deprecated since version . . ." warning instead? Maybe a comprimise would be to "hide" its documentation away in a separate deprecated section or something. Well, I wasn't proposing a deprecation (although that can be done as well, if we want). I was proposing that this detail be hidden. I don't know if it would make existing software harder to understand. I don't think I've ever seen an actively-maintained project that used runTest(). The simple way to hide it would be to stop documenting the TestCase constructor and its signature. You aren't supposed to instantiate TestCase yourself. |
|||
| msg230191 - (view) | Author: Robert Collins (rbcollins) * (Python committer) | Date: 2014年10月29日 00:25 | |
Constructing test case objects directly is part of the protocol, and its needed for framework and extension authors. I've seen folk use runTest, but rarely enough that I think we could deprecate it. My argument is that while its supported we should be clear about when it should be used, and how. |
|||
| msg230231 - (view) | Author: Robert Collins (rbcollins) * (Python committer) | Date: 2014年10月29日 18:50 | |
Oh, one thought - in testtools we split out 'docs for test writers' and 'docs for framework folk'. That would facilitate getting runTest out of test writers face while still documenting it appropriately. Related to that is my ongoing push to split the protocol so that these concerns are not intertwined the way they are today, but that needs to wait for the existing backlog to clear up :) |
|||
| msg230312 - (view) | Author: Robert Collins (rbcollins) * (Python committer) | Date: 2014年10月30日 23:53 | |
I'll apply the patch monday if there are no further comments before then. |
|||
| msg230352 - (view) | Author: Ezio Melotti (ezio.melotti) * (Python committer) | Date: 2014年10月31日 16:55 | |
> Oh, one thought - in testtools we split out 'docs for test writers' and > 'docs for framework folk'. That would facilitate getting runTest out of > test writers face while still documenting it appropriately. This has already been discussed in the past, and IIRC there was consensus about giving unittest docs the same treatment. I don't remember if there was an issue for this. |
|||
| msg232226 - (view) | Author: Martin Panter (martin.panter) * (Python committer) | Date: 2014年12月05日 23:53 | |
Updated patch with indentation fixed and new wording. I am just guessing the RST syntax based on the surrounding text, so please review :) |
|||
| msg232260 - (view) | Author: Martin Panter (martin.panter) * (Python committer) | Date: 2014年12月06日 23:58 | |
Updated patch, which applies to current tip of the default branch, and includes the formatting fix. Also including a version that applies to the 3.4 branch. Alternatively, if you patch the 3.4 branch it looks like merging to default automatically gives the correct result. |
|||
| msg247143 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2015年07月22日 18:40 | |
New changeset eefc157b3096 by Robert Collins in branch '3.4': Issue #22153: Improve unittest docs. Patch from Martin Panter and evilzero. https://hg.python.org/cpython/rev/eefc157b3096 New changeset 10f5a7fa26d5 by Robert Collins in branch '3.5': Issue #22153: Improve unittest docs. Patch from Martin Panter and evilzero. https://hg.python.org/cpython/rev/10f5a7fa26d5 New changeset 45bd2dadbd0d by Robert Collins in branch 'default': Issue #22153: Improve unittest docs. Patch from Martin Panter and evilzero. https://hg.python.org/cpython/rev/45bd2dadbd0d |
|||
| msg247145 - (view) | Author: Robert Collins (rbcollins) * (Python committer) | Date: 2015年07月22日 18:43 | |
Thanks for the update, it looks good to me. Applied to 3.4 and up. I'm not applying to 2.7 at this stage. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:58:06 | admin | set | github: 66349 |
| 2015年07月22日 19:25:05 | rbcollins | set | status: open -> closed stage: commit review -> resolved resolution: fixed versions: + Python 3.6, - Python 2.7 |
| 2015年07月22日 18:43:08 | rbcollins | set | messages: + msg247145 |
| 2015年07月22日 18:40:40 | python-dev | set | nosy:
+ python-dev messages: + msg247143 |
| 2014年12月06日 23:58:33 | martin.panter | set | files: + runTest2-3.4.patch |
| 2014年12月06日 23:58:20 | martin.panter | set | files:
+ runTest2-default.patch messages: + msg232260 |
| 2014年12月06日 16:31:42 | berker.peksag | set | nosy:
+ berker.peksag stage: patch review -> commit review |
| 2014年12月05日 23:53:07 | martin.panter | set | files:
+ runtest.patch messages: + msg232226 |
| 2014年10月31日 16:55:48 | ezio.melotti | set | messages: + msg230352 |
| 2014年10月30日 23:53:52 | rbcollins | set | messages: + msg230312 |
| 2014年10月29日 19:00:06 | rbcollins | set | title: There is no standard TestCase.runTest implementation -> Documentation of TestCase.runTest is incorrect and confusing |
| 2014年10月29日 18:50:59 | rbcollins | set | messages: + msg230231 |
| 2014年10月29日 00:25:21 | rbcollins | set | messages: + msg230191 |
| 2014年10月29日 00:16:45 | pitrou | set | messages: + msg230190 |
| 2014年10月28日 23:22:50 | martin.panter | set | messages: + msg230188 |
| 2014年10月28日 22:06:08 | pitrou | set | messages: + msg230182 |
| 2014年10月28日 22:01:05 | rbcollins | set | messages: + msg230181 |
| 2014年10月28日 21:57:20 | martin.panter | set | messages: + msg230180 |
| 2014年10月28日 13:16:18 | pitrou | set | nosy:
+ pitrou messages: + msg230147 |
| 2014年10月28日 10:52:31 | martin.panter | set | messages: + msg230137 |
| 2014年10月28日 09:14:04 | ezio.melotti | set | nosy:
+ rbcollins stage: patch review versions: + Python 2.7 |
| 2014年08月17日 20:01:10 | evilzero | set | type: enhancement |
| 2014年08月17日 20:00:18 | evilzero | set | files:
+ myworkdoc.patch nosy: + evilzero messages: + msg225466 keywords: + patch |
| 2014年08月08日 19:38:33 | terry.reedy | set | nosy:
+ ezio.melotti, michael.foord |
| 2014年08月06日 05:00:02 | martin.panter | create | |