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: Option to not-exit on test
Type: enhancement Stage: patch review
Components: Library (Lib), Tests Versions: Python 3.1, Python 2.7
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: barry Nosy List: barry, benjamin.peterson, georg.brandl, michael.foord, pupeno
Priority: normal Keywords: patch

Created on 2008-07-16 15:13 by pupeno, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
add_avoid_exit_option.diff pupeno, 2008-07-16 17:51 Patch to add sption to not-exit on test
add_avoid_exit_option.diff pupeno, 2008-07-16 18:25 Patch to add sption to not-exit on test, including documentation
add_avoid_exit_option.diff pupeno, 2008-07-17 17:48 Patch to add sption to not-exit on test, including documentation and tests
unittest-no-exit.patch michael.foord, 2009-04-26 21:03
Messages (17)
msg69791 - (view) Author: J. Pablo Fernández (pupeno) Date: 2008-07-16 15:13
Added an option, called exit, that when set to false, will make the
tests not exit at the end. This is useful when you are doing Lisp-like
development having a REPL (interpreter/prompt) opened in Emacs and
running the tests over and over on it.
Currently, the tests will exit the interpreter, causing the in-Emacs
interpreter to close as well.
It is by default set to false, so the default behavior is still the
same. When set to true the default behavior shouldn't change much
because at the end of the tests you are going to exit anyway. The only
difference is that no exit code will be provided. There's actually
something else, because the Python test suite hangs in a test case when
this is set to true, but this should be of no concern, as default is false.
msg69792 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-07-16 15:20
This is related to (maybe a duplicate of) #2674.
msg69808 - (view) Author: J. Pablo Fernández (pupeno) Date: 2008-07-16 18:11
Indeed this patch can be considered a fix for #2674, but, it should be
documented appropriately. Should that be in
http://docs.python.org/dev/3.0/library/unittest.html ?
msg69809 - (view) Author: J. Pablo Fernández (pupeno) Date: 2008-07-16 18:25
Added some documentation.
msg69896 - (view) Author: J. Pablo Fernández (pupeno) Date: 2008-07-17 17:48
Added tests.
msg69991 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-07-18 21:28
Barry, this looks useful and shouldn't be at all disruptive even after
beta2. May I check it in?
msg69994 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2008-07-18 21:45
I'm not sure it's a good idea.  When exit=False, don't you lose the
results?  It would be better to return the results, but then that makes
for an ugly API (changing the return value based on an argument is a
general no-no in Python).

It would seem better to add a new method that returned the results
instead of exiting.  You'd probably want to refactor runTests().
msg70032 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-07-19 13:52
Well, the results are displayed on stdout like they are if sys.exit is
used. As the first post explains, the use-case is running the tests from
an interactive interpreter.
msg70038 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2008-07-19 15:29
I still think a different method would be better for the no-exit
functionality.
msg70172 - (view) Author: J. Pablo Fernández (pupeno) Date: 2008-07-23 13:17
What about always returning the results. Granted, when sys.exit is run
there will be no results returned, but then nothing to get the results.
If we divided in two functions, would one be unittest.main and the other
unittest.nonExitingMain? Sounds ugly, but OK if no other better way is
possible.

I personally believe that main should not hijack the current interpreter
with sys.exit at all, but I understand that behavior is not changeable
at the moment (is it?).
msg85726 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2009-04-07 16:06
Not returning the results is not a problem - if you needed access to the
results you would hardly be using this API in the first place.

The obvious use case if for running tests from an interactive
environment where you are using the visual output on stdout.

If you want to collect the results you do it programmatically.

I wouldn't be opposed to main() returning the results though, but think
we should apply the patch rather than debate further. To action!
msg86565 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2009-04-25 22:59
Patch that adds the same exit functionality, but also stores the result
as an instance attribute on the return TestProgram instance.

As this functionality has been requested several times my intention is
to apply this patch.
msg86566 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-04-25 23:04
Michael, this patch seems to include extra addCleanup() stuff.
msg86605 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2009-04-26 21:00
Damn somehow managed to upload the patch to the wrong issue twice in a
row. Must have been late at night.
msg86606 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2009-04-26 21:03
Correct patch this time. If there are no objections I'll apply this in a 
couple of days.
msg86940 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2009-05-02 12:15
Committed in revision 71291.
msg86941 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2009-05-02 12:16
No, make that revision 72191. :-)
History
Date User Action Args
2022-04-11 14:56:36adminsetgithub: 47629
2009-05-02 12:16:25michael.foordsetmessages: + msg86941
2009-05-02 12:15:35michael.foordsetstatus: open -> closed

messages: + msg86940
2009-04-26 21:03:17michael.foordsetfiles: + unittest-no-exit.patch

messages: + msg86606
2009-04-26 21:00:13michael.foordsetmessages: + msg86605
2009-04-26 20:59:43michael.foordsetfiles: - unittest-no-exit.patch
2009-04-25 23:04:51benjamin.petersonsetmessages: + msg86566
2009-04-25 22:59:50michael.foordsetfiles: + unittest-no-exit.patch

messages: + msg86565
2009-04-07 16:06:29michael.foordsetnosy: + michael.foord
messages: + msg85726
2009-04-07 16:05:23ajaksu2linkissue2674 superseder
2009-04-07 16:01:56ajaksu2setpriority: normal
stage: patch review
components: + Tests
versions: + Python 3.1, Python 2.7, - Python 3.0
2009-04-07 16:01:09ajaksu2linkissue1774840 superseder
2008-07-23 13:17:36pupenosetmessages: + msg70172
2008-07-19 15:29:54barrysetmessages: + msg70038
2008-07-19 13:52:20georg.brandlsetmessages: + msg70032
2008-07-18 21:45:50barrysetmessages: + msg69994
2008-07-18 21:28:13georg.brandlsetassignee: barry
messages: + msg69991
nosy: + barry, georg.brandl
2008-07-17 17:48:03pupenosetfiles: + add_avoid_exit_option.diff
messages: + msg69896
2008-07-16 18:25:33pupenosetfiles: + add_avoid_exit_option.diff
messages: + msg69809
2008-07-16 18:11:29pupenosetmessages: + msg69808
2008-07-16 17:51:37pupenosetfiles: - add_avoid_exit_option.diff
2008-07-16 17:51:30pupenosetfiles: + add_avoid_exit_option.diff
2008-07-16 15:20:59benjamin.petersonsetnosy: + benjamin.peterson
messages: + msg69792
2008-07-16 15:13:21pupenocreate