Issue 1244929: hide tests from TestProgram (original) (raw)

Created on 2005-07-26 03:54 by ehuss, last changed 2022-04-11 14:56 by admin. 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
2022-04-11 14:56:12 admin set github: 42221
2009-06-02 17:50:55 michael.foord set status: open -> closedresolution: wont fixmessages: +
2009-05-15 02:49:00 ajaksu2 set nosy: + michael.foordversions: + Python 3.2
2009-02-17 07:41:29 amaury.forgeotdarc set nosy: + amaury.forgeotdarcmessages: +
2009-02-16 02:26:20 ajaksu2 set versions: + Python 2.7, - Python 2.6nosy: + ajaksu2messages: + components: + Teststype: enhancementstage: test needed
2005-07-26 03:54:02 ehuss create