case.py 1.3 KB

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