case.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Copyright (C) 2016 Intel Corporation
  2. # Released under the MIT license (see COPYING.MIT)
  3. import unittest
  4. from oeqa.core.exception import OEQAMissingVariable
  5. def _validate_td_vars(td, td_vars, type_msg):
  6. if td_vars:
  7. for v in td_vars:
  8. if not v in td:
  9. raise OEQAMissingVariable("Test %s need %s variable but"\
  10. " isn't into td" % (type_msg, v))
  11. class OETestCase(unittest.TestCase):
  12. # TestContext and Logger instance set by OETestLoader.
  13. tc = None
  14. logger = None
  15. # td has all the variables needed by the test cases
  16. # is the same across all the test cases.
  17. td = None
  18. # td_vars has the variables needed by a test class
  19. # or test case instance, if some var isn't into td a
  20. # OEQAMissingVariable exception is raised
  21. td_vars = None
  22. @classmethod
  23. def _oeSetUpClass(clss):
  24. _validate_td_vars(clss.td, clss.td_vars, "class")
  25. clss.setUpClassMethod()
  26. @classmethod
  27. def _oeTearDownClass(clss):
  28. clss.tearDownClassMethod()
  29. def _oeSetUp(self):
  30. for d in self.decorators:
  31. d.setUpDecorator()
  32. self.setUpMethod()
  33. def _oeTearDown(self):
  34. for d in self.decorators:
  35. d.tearDownDecorator()
  36. self.tearDownMethod()