On 8/15/06, Fergal Daly <[EMAIL PROTECTED]> wrote:
Where this becomes more important is when you start constructing
suites automatically. For example

class SomeTest(unittest.TestCase):
  def __init__(self, data):
    self.data = data
    unittest.TestCase.__init__(self)

  def test_foo(self):
    # some tests on self.data

  def test_bar(self):
    # some tests on self.data

list_of_data = [ ... ]
suite = unittest.TestSuite()
for data in list_of_data:
  suite.addTest( SomeTest(data) )

suite.run()

now my suite looks like

suite
  SomeTest
  SomeTest
  ...
  SomeTest

line numbers are no good to me. I haven't ever done this in Python but
I've done the equivalent in Perl. Basically as soon as you want to
have tests that are driven by data sets rather than tests that are all
explicitly written you need structure. It's also necessary for code
reuse.

The solution to this particular issue would be to have your SomeTest
class override TestCase.id(), TestCase.__str__() and/or
TestCase.__repr__() to take into account the data attribute.

On the other hand, I can see scenarios where being able to indicate
which suite a test is in, for example, tests that depend on being run in a
certain order.

Collin Winter

Reply via email to