classification
Title: hide tests from TestProgram
Type: enhancement Stage: test needed
Components: Library (Lib), Tests Versions: Python 3.2, Python 2.7
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: collinwinter Nosy List: ajaksu2, amaury.forgeotdarc, collinwinter, ehuss, michael.foord
Priority: normal Keywords: patch

Created on 2005-07-26 03:54 by ehuss, last changed 2009-06-02 17:50 by michael.foord. This issue is now closed.

Files
File name Uploaded Description Edit
unittest.patch ehuss, 2005-07-26 03:54 Patch to unittest to ignore classes starting with an underscore.
Messages (4)
msg48631 - (view) Author: Eric Huss (ehuss) Date: 2005-07-26 03:54
The TestProgram class will find all tests in the file 
based on whether or not they are subclassed from 
TestCase.  It is not possible to prevent TestProgram 
from including tests, such as base classes.

For example, have BaseTest(unittest.TestCase) class 
that implements several test functions.  However, these 
test functions can not operate correctly on their 
own...the class must be subclassed for proper operation 
(such as TestBlah(BaseTest)).

This patch changes the "auto find" feature to ignore any 
classes that start with an underscore, allowing you to 
define base classes in the same file, but not have their 
tests run.
msg82208 - (view) Author: Daniel Diniz (ajaksu2) (Python triager) Date: 2009-02-16 02:26
I think this feature is already present in current unittest, can anyone
confirm?
msg82302 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2009-02-17 07:41
No, the feature is not present in current unittest; the patch is still 
applicable. I'm concerned with backward compatibility, though.

To achieve the same result, the common usage is a mixin class.
See for example Lib/test/test_codecencoding_cn.py:

class BaseTest:
    ... test functions, setup, teardown ...
class TestBlah(BaseTest, unittest.TestCase):
    ... subclass here ...

This is not too bad. I suggest to close this issue as "won't fix".
msg88758 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2009-06-02 17:50
A module can now define load_tests (used by loadTestsFromModule) and
exclude certain classes itself.
History
Date User Action Args
2009-06-02 17:50:55michael.foordsetstatus: open -> closed
resolution: wont fix
messages: + msg88758
2009-05-15 02:49:00ajaksu2setnosy: + michael.foord

versions: + Python 3.2
2009-02-17 07:41:29amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg82302
2009-02-16 02:26:20ajaksu2setversions: + Python 2.7, - Python 2.6
nosy: + ajaksu2
messages: + msg82208
components: + Tests
type: enhancement
stage: test needed
2005-07-26 03:54:02ehusscreate