msg176832 - (view) |
Author: anatoly techtonik (techtonik) |
Date: 2012-12-03 09:42 |
A common usage pattern is to prevent clean up in tearDown() if the test failed. However, it requires a hack: http://stackoverflow.com/questions/4414234/getting-pythons-unittest-results-in-a-teardown-method. Would be nice to have an officially documented feature. |
|
|
msg176901 - (view) |
Author: Antoine Pitrou (pitrou) *  |
Date: 2012-12-04 12:06 |
Another solution would be to add a new method named addSuccessCleanup. |
|
|
msg176902 - (view) |
Author: anatoly techtonik (techtonik) |
Date: 2012-12-04 12:08 |
Or call tearDown() with some parameter that it's able to retrieve. |
|
|
msg176904 - (view) |
Author: Michael Foord (michael.foord) *  |
Date: 2012-12-04 12:09 |
Changing the signature of tearDown would be backwards incompatible. addSuccessCleanup is an interesting idea - cleanup functions that are only executed if the test passes. (What to do if a cleanup function raises an exception though? And when do these get executed - before or after standard cleanups.) In general cleanup functions are an improvement on tearDown. |
|
|
msg176906 - (view) |
Author: anatoly techtonik (techtonik) |
Date: 2012-12-04 12:40 |
addSuccessCleanup is not the best name as it assumes that some cleanup is being added, which is confusing. Additional consideration that the need to leave the test results is a user run time preference, which may only be actual when debugging or working on the particular test. |
|
|
msg176908 - (view) |
Author: Michael Foord (michael.foord) *  |
Date: 2012-12-04 12:43 |
Well, addSuccessCleanup *would* be an api for adding a cleanup - one that is only called on success. So the cleanup is skipped on failure or error, which was the original use case. "Additional consideration that the need to leave the test results is a user run time preference, which may only be actual when debugging or working on the particular test." I can't parse that sentence, can you rephrase please. (Did you mean another word other than "leave", and I don't understand "may only be actual".) |
|
|
msg176909 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2012-12-04 12:45 |
Why do you need it? You can add a test result depended code at the end of the test method. For example set a special flag def setUp(self): self.success = False def tearDown(self): if not self.success: ... def test_xxx(self): ... self.success = True I don't think any special support in stdlib needed. |
|
|
msg176919 - (view) |
Author: anatoly techtonik (techtonik) |
Date: 2012-12-04 15:10 |
On Tue, Dec 4, 2012 at 3:43 PM, Michael Foord <report@bugs.python.org>wrote: > > Well, addSuccessCleanup *would* be an api for adding a cleanup - one that > is only called on success. So the cleanup is skipped on failure or error, > which was the original use case. > I thought it will be a callback method. > "Additional consideration that the need to leave the test results is a > user run time preference, which may only be actual when debugging or > working on the particular test." > > I can't parse that sentence, can you rephrase please. (Did you mean > another word other than "leave", and I don't understand "may only be > actual".) > Most of the time users need to clean up mess. It mostly during debug session you need to leave it. So the workaround should be easy and obvious to enable and disable. Serhiy's method is good. I was too busy with other stuff to think about it. Thanks. |
|
|
msg178236 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2012-12-26 18:47 |
Anatoly, if this is good for you, please close the issue. |
|
|
msg178341 - (view) |
Author: Chris Jerdonek (chris.jerdonek) *  |
Date: 2012-12-27 22:01 |
I agree with Serhiy here. This use case seems too specialized, and there are easy ways to achieve the same thing in code. |
|
|
msg222102 - (view) |
Author: Mark Lawrence (BreamoreBoy) * |
Date: 2014-07-02 13:25 |
The solution suggested in seems accepted all around so can we please close this. |
|
|