I am automatically generating unit tests for some Python code which number in the thousands. The unittest
module uses classes to contain the tests however I'm guessing there is an upper limit to the number of methods a class may contain - is this the case?
Methods (and in fact all attributes) of a class are stored in a dict
. There is no limit to the number of items a dict
can contain, save that each key must be unique.
I strongly doubt that you'd ever hit the limit, even if there was one. As far as I know though, the number of methods an object can have is limited only by memory. I just defined a class with a million functions, with no problem. Try this if you don't believe me:
>>> class C(object): pass
>>> for i in xrange(10**6):
exec('C.func%d=lambda self: %d'%(i,i))
>>> c = C()
>>> c.func1()
1
>>> c.func999999()
999999
If your class has more than a million functions (hell, or more than a dozen or so), you have other problems.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With