homepage

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: unittest: Access test result from tearDown
Type: enhancement Stage: resolved
Components: Library (Lib), Tests Versions: Python 3.5
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: michael.foord Nosy List: BreamoreBoy, chris.jerdonek, jcea, michael.foord, pitrou, serhiy.storchaka, techtonik
Priority: normal Keywords:

Created on 2012年12月03日 09:42 by techtonik, last changed 2022年04月11日 14:57 by admin. This issue is now closed.

Messages (11)
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) * (Python committer) 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) * (Python committer) 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) * (Python committer) 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) * (Python committer) 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) * (Python committer) Date: 2012年12月26日 18:47
Anatoly, if this is good for you, please close the issue.
msg178341 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) 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 msg176909 seems accepted all around so can we please close this.
History
Date User Action Args
2022年04月11日 14:57:39adminsetgithub: 60803
2014年08月22日 09:35:26Claudiu.Popasetstatus: open -> closed
resolution: rejected
stage: needs patch -> resolved
2014年07月02日 13:25:06BreamoreBoysetnosy: + BreamoreBoy

messages: + msg222102
versions: + Python 3.5, - Python 3.4
2012年12月27日 22:01:57chris.jerdoneksetnosy: + chris.jerdonek
messages: + msg178341
2012年12月26日 18:47:44serhiy.storchakasetmessages: + msg178236
2012年12月04日 15:10:50techtoniksetmessages: + msg176919
2012年12月04日 12:45:08serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg176909
2012年12月04日 12:43:38michael.foordsetmessages: + msg176908
2012年12月04日 12:40:49techtoniksetmessages: + msg176906
2012年12月04日 12:09:51michael.foordsetassignee: michael.foord
messages: + msg176904
2012年12月04日 12:08:07techtoniksetmessages: + msg176902
2012年12月04日 12:06:42pitrousetnosy: + michael.foord, pitrou
messages: + msg176901
2012年12月03日 14:53:52jceasetnosy: + jcea
2012年12月03日 10:05:02daniel.urbansetstage: needs patch
type: enhancement
versions: + Python 3.4, - Python 3.1, Python 2.7, Python 3.2, Python 3.3
2012年12月03日 09:42:03techtonikcreate

AltStyle によって変換されたページ (->オリジナル) /