I have what I hope to be a pretty general question. I am testing XML files and validating specific tags. I didn't want to re-write the code for each field so I am trying to reuse the tag checking code. However, when I try to do so
Here is the "ValidateField" class that I am trying to use the UnitTest Framework in. This is the code I am trying to use. I am simply trying to call it as follows. What I get is that the unit test framework ran 0 tests. I am sucessfully using the unit test framework elsewhere in my program where I am not trying to reuse a class. Anyone now where I am going astray?
Here is the output I get:
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
----------------------------------------------------------------------
Here is the class/Method where I am making the call to the reusable class
import Common.ValidateField
class Tests():
def test_testCreated(self):
validate = Common.ValidateField.ValidateField()
validate.test_field('./created')
Here is the reusable class using the unit test framework.
import unittest
import Main
import Common.Logger
class ValidateField(unittest.TestCase):
def test_field(self, xpath):
driver = Main.ValidateDriver().driver
logger = Common.Logger.Logger
tag = []
for t in driver.findall("'" + xpath + "'"):
tag.append(t)
# Test to see if there is more than one tag.
if len(tag) > 1:
self.assertTrue(False, logger.failed("There is more than one " + "'" + t.text + "'" + " tag."))
else:
# Test for a missing tag.
if len(tag) <= 0:
self.assertTrue(False, logger.failed("There is no " + "'" + t.text + "'" + " tag."))
# Found the correct number of tags.
self.assertTrue(True, logger.passed("There is only one " + "'" + t.text + "'" + " tag."))
# Test to make sure there is actually something in the tag.
if t.text is None:
self.assertTrue(False, logger.failed("There is a " + "'" + t.text + "'" + " tag, but no value exists"))