Python unittest not recognizing tests -
i'm trying learn how use unittest
framework in python. keep getting message below when run file containing tests.
---------------------------------------------------------------------- ran 0 tests in 0.000s ok
i've searched here , elsewhere , can't figure out why not recognizing tests. each test starts test
, other portions of unittest
seem match documentation requires.
here text of script:
import unittest datetime import datetime, timedelta class activity(object): 'holds detail information on activity' def __init__(self, location, activity_name, activity_id, start_date, end_date): self.activity_name = activity_name self.activity_id = activity_id self.start_date = datetime.strptime(start_date, '%m/%d/%y').date() self.end_date = datetime.strptime(end_date, '%m/%d/%y').date() self.location = location if __name__ == '__main__': unittest.main() class testactivity(unittest.testcase): def setup(self): self.activity = activity('uvu', 'openwest', 'beginning python' , '00000', '12/1/2013', '12/30/3013') def test_activity_creation(self): self.assertequal(self.activity.location, 'uvu') self.assertequal(self.activity.activity_name, 'openwest') self.assertequal(self.activity.activity_id, '00000') self.assertequal(self.activity.start_date, datetime.strptime('12/1/2013', '%m/%d/%y').date()) self.assertequal(self.activity.start_date, datetime.strptime('12/30/2013', '%m/%d/%y').date()) def test1(self): self.assertequal(1,1) def teardown(self): del self.activity
any appreciated
if move
if __name__ == '__main__': unittest.main()
to end of script, work.
update
here speculation: when called unittest.main()
in middle of script, test class has not been defined yet, unittest
did not pick tests. moving unittest.main()
end, or more precisely--after define test class, make sure unittest
sees tests.
Comments
Post a Comment