Re-running unittest

Israel Fernández Cabrera iferca at gmail.com
Sun Jul 22 16:43:03 EDT 2007


Hi
I'm writing some code that automatically execute some registered unit
test in a way to automate the process. A sample code follows to
illustrate what I'm doing:

<code requires="save as import_tests.py">
class PruebasDePrueba(unittest.TestCase):
   def testUnTest(self):
       a = 2
       b = 1
       self.assertEquals(a, b)

def runTests():
   loader = unittest.TestLoader()
   result = unittest.TestResult()
   suite = loader.loadTestsFromName("import_tests.PruebasDePrueba")
   suite.run(result)
   print "Errores: ", len(result.errors)
   print "Fallos: ", len(result.failures)

if __name__ == "__main__":
   runTests()
   raw_input("Modify [fix] the test and press ENTER to continue")
</code>

The code executes the tests from the class PruebasDePrueba, as the
user to "fix" the failing test and then executes the tests again after
ENTER is pressed.
The test's initial state is "fail" so, equaling the values of a or b
in the second execution I wait the test does not fails again, but it
does.
I've changed the original code in very different ways trying to figure
out what is wrong with it but no success
The problem is not reproduced if instead of loading the test from the
TestCase (import_tests.PruebasDePrueba) they are loaded referring the
container module and this behaves like this because I wrote a class
that inherits from unittest.TestLoader abd re-defines the
loadTestsFromModule(module) then every time this method is called, the
module is reloaded via "reload" python's function. I would like to do
the same with TestCases.

I have written this problem to several other python lists but I have
not received any answer, hope this time is different,
I'd like to thaks in advance, regards


-- 
____________________
Israel Fdez. Cabrera
iferca at gmail.com

 . 0 .
 . . 0
 0 0 0



More information about the Python-list mailing list