[Patches] [ python-Patches-736962 ] Port tests to unittest (Part 2)
SourceForge.net
noreply@sourceforge.net
Sat, 17 May 2003 18:59:10 -0700
Patches item #736962, was opened at 2003-05-13 05:45
Message generated for change (Comment added) made by rhettinger
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=736962&group_id=5470
Category: Tests
Group: None
Status: Open
Resolution: Accepted
Priority: 5
Submitted By: Walter Dörwald (doerwalter)
Assigned to: Walter Dörwald (doerwalter)
Summary: Port tests to unittest (Part 2)
Initial Comment:
Here are the next test scripts ported to PyUnit:
test_winsound and test_array. For test_array many
additional tests have been added (code coverage is at 91%)
----------------------------------------------------------------------
>Comment By: Raymond Hettinger (rhettinger)
Date: 2003-05-17 20:59
Message:
Logged In: YES
user_id=80475
Good call.
Instead of using metaclasses, perhaps add a module
introspector function to test_support:
def findtestclasses(mod):
tests = []
for elem in dir(mod):
member = getattr(mod, elem)
if type(member) != type: continue
if issubclass(member, unittest.TestCase):
tests.append(member)
return tests
----------------------------------------------------------------------
Comment By: Walter Dörwald (doerwalter)
Date: 2003-05-17 20:45
Message:
Logged In: YES
user_id=89016
But this can be solved with a special non-inheritable class
attribute:
class BaseTest(unittest.TestCase):
run = False
Then the metaclass can do the following:
def __new__(cls, name, bases, dict):
if "run" not in dict:
dict["run"] = True
cls = type.__new__(cls, name, bases, dict)
if cls.run:
tests.append(cls)
return cls
----------------------------------------------------------------------
Comment By: Raymond Hettinger (rhettinger)
Date: 2003-05-17 20:04
Message:
Logged In: YES
user_id=80475
I don't think metaclasses or module introspection would
help whenever there are classes that derive from TestCase
but are not meant to be run directly (their subclasses have
the setup/teardown/or class data). test_sets.py has
examples of that kind of thing.
----------------------------------------------------------------------
Comment By: Walter Dörwald (doerwalter)
Date: 2003-05-17 19:50
Message:
Logged In: YES
user_id=89016
Checked in as:
Lib/test/test_array.py 1.20
Lib/test/test_winsound.py 1.5
Lib/test/output/test_winsound delete
> The approach of using tests.append() is elegant and
> makes it easier to verify that no tests are being omitted.
The most elegant approach would probably be a metaclass that
collects all TestCase subclasses that get defined. Classes
that only serve as a base class could be skipped by
specifying a certain class attribute.
----------------------------------------------------------------------
Comment By: Raymond Hettinger (rhettinger)
Date: 2003-05-17 18:35
Message:
Logged In: YES
user_id=80475
The approach of using tests.append() is elegant and
makes it easier to verify that no tests are being omitted.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=736962&group_id=5470