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: Wrapped TestSuite subclass does not get __call__ executed
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.2, Python 2.7
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: michael.foord Nosy List: loewis, michael.foord
Priority: normal Keywords: patch

Created on 2010-09-23 14:32 by loewis, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
suite.diff michael.foord, 2010-09-25 22:42 Tag result in TestSuite.run review
Messages (9)
msg117192 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2010-09-23 14:32
In Python 3.2, when inheriting from TestSuite, it is no longer possible to override __call__ (e.g. to introduce a TestSuite setUp and tearDown).
The __call__ method will not be called anymore.

Instead, if the object has a _wrapped_run defined (which it will, since it inherits from TestSuite), then this is called instead. Overriding _wrapped_run is a work-around, however, this being a private method, overriding it is probably not a good idea.
msg117198 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2010-09-23 15:46
Right, _wrapped_run is private and not intended to be overridden. 

Perhaps slightly ironically (for this particular bug report) is that the change was introduced to support class and module level setUp and tearDown (similar to the use-case it now blocks).

Another workaround would be to inherit from BaseTestSuite (which would disable the class and module level fixture support).

A backwards compatible change would be to rename BaseTestSuite *back* to TestSuite and give the current TestSuite a new name. This means that the new class / module level fixtures would only be supported in code that gets suites from the TestLoader (which uses the new class) or by creating suites using the new class.

The disadvantage of this approach is that it is not uncommon for test frameworks to create suites themselves - and doing this could 'break' tests using class / module fixtures.

The reason for the change is that in order to tearDown the final class and module level fixtures we need to know when we exit the 'top level' of a run from inside a suite.

Any other suggestions or ideas?

(Another idea is to add explicit setUp and tearDown hooks to the TestSuite object. This isn't backwards compatible but meets the direct use case. Obviously backwards compatibility is greatly preferable.)
msg117201 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2010-09-23 15:51
Hmmm... 2.7 has already been released and has the same issue, so 'drastic' changes (like renaming BaseTestSuite back to TestSuite) are probably out.
msg117304 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2010-09-24 16:11
Ok, so here is an idea that could remove the need for TestSuite._wrapped_run. 

TestSuite.run could "tag" the result object (set an attribute). Nested TestSuites would see an already tagged suite and do nothing (beyond running tests of course). The suite that does the tagging would call the necessary module / class level test suites on exit.
msg117322 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2010-09-24 18:23
> Perhaps slightly ironically (for this particular bug report) is that
> the change was introduced to support class and module level setUp and
> tearDown (similar to the use-case it now blocks).

FWIW, this issue arrived from pygresql, see TestSuite2 in
http://tinyurl.com/2ap9t6d

Here, the objective is to wrap a number of test suite classes
with a single setup/teardown, covering all test cases that occur
in either test suite, so that the expensive database creation
happens only once. I can't see how either class or module level
setup could easily replace this.

> A backwards compatible change would be to rename BaseTestSuite *back*
> to TestSuite and give the current TestSuite a new name.

That sounds good to me.

> The disadvantage of this approach is that it is not uncommon for test
> frameworks to create suites themselves - and doing this could 'break'
> tests using class / module fixtures.

You mean, for test suites that have been modified to explicitly
support Python 2.7?

> Any other suggestions or ideas?

I think this would then be for python-dev to discuss.
msg117340 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2010-09-24 22:33
On 24/09/2010 19:23, Martin v. Löwis wrote:
> Martin v. Löwis<martin@v.loewis.de>  added the comment:
>> Perhaps slightly ironically (for this particular bug report) is that
>> the change was introduced to support class and module level setUp and
>> tearDown (similar to the use-case it now blocks).
> FWIW, this issue arrived from pygresql, see TestSuite2 in
> http://tinyurl.com/2ap9t6d

Thanks.

Heh, well - allowing multiple testcases to share fixtures like expensive 
databases was one of the primary use cases given for introducing 
setUpModule and setUpClass.

>> A backwards compatible change would be to rename BaseTestSuite *back*
>> to TestSuite and give the current TestSuite a new name.
> That sounds good to me.
>

As I mentioned, the introduction of _wrapped_run to TestSuite has been 
released in Python 2.7 - so I don't think that we can pursue this option.

>> The disadvantage of this approach is that it is not uncommon for test
>> frameworks to create suites themselves - and doing this could 'break'
>> tests using class / module fixtures.
> You mean, for test suites that have been modified to explicitly
> support Python 2.7?
>

No, I just mean that directly creating test collections using TestSuite 
is a common thing for test frameworks to do. If the base TestSuite 
didn't support class / module fixtures then these test frameworks would 
no longer be able to use these features.

>> Any other suggestions or ideas?
> I think this would then be for python-dev to discuss.
>

I think the result tagging idea will work both as a bugfix for 2.7 and 
3.2. I'll work on a  patch and test. If it doesn't work we can take it 
to python-dev, but bearing in mind that we have to remain compatible 
with the released 2.7 as well (i.e. not changing the behaviour of 
TestSuite drastically).
msg117396 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2010-09-25 22:42
The attached patch fixes the issue (I think...) by tagging the result object. It removes the need for _wrapped_result altogether. The test fails without the change to TestSuite and passes with the change.

This could be applied to 2.7-maint and py3k.

Uhm... the patch needs a better name for the TestResult tag attribute.
msg120176 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2010-11-01 21:16
Committed to py3k in revision 86101. Needs porting to Python 2.7 (and unittest2).
msg120184 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2010-11-01 22:12
Committed to release27-maint in revision 86104.
History
Date User Action Args
2022-04-11 14:57:06adminsetgithub: 54135
2010-11-01 22:12:44michael.foordsetstatus: open -> closed
resolution: accepted
messages: + msg120184

stage: resolved
2010-11-01 21:16:47michael.foordsetmessages: + msg120176
2010-09-25 22:42:51michael.foordsetfiles: + suite.diff
keywords: + patch
messages: + msg117396
2010-09-24 22:33:02michael.foordsetmessages: + msg117340
2010-09-24 18:23:29loewissetmessages: + msg117322
2010-09-24 16:11:03michael.foordsetmessages: + msg117304
2010-09-23 15:51:03michael.foordsetmessages: + msg117201
components: + Library (Lib)
versions: + Python 2.7
2010-09-23 15:46:43michael.foordsetmessages: + msg117198
2010-09-23 14:32:46loewiscreate