/functional_tests/test_load_tests_from_test_case.py

https://bitbucket.org/jpellerin/nose/ · Python · 56 lines · 38 code · 13 blank · 5 comment · 3 complexity · 3ea767e545f2862079b356d0ad5bfb7b MD5 · raw file

  1. """
  2. Tests that plugins can override loadTestsFromTestCase
  3. """
  4. import os
  5. import unittest
  6. from nose import loader
  7. from nose.plugins import PluginTester
  8. from nose.plugins.base import Plugin
  9. support = os.path.join(os.path.dirname(__file__), 'support')
  10. class NoFixturePlug(Plugin):
  11. enabled = True
  12. def options(self, parser, env):
  13. print "options"
  14. pass
  15. def configure(self, options, conf):
  16. print "configure"
  17. pass
  18. def loadTestsFromTestCase(self, testCaseClass):
  19. print "Called!"
  20. class Derived(testCaseClass):
  21. def setUp(self):
  22. pass
  23. def tearDown(self):
  24. pass
  25. # must use nose loader here because the default loader in 2.3
  26. # won't load tests from base classes
  27. l = loader.TestLoader()
  28. return l.loadTestsFromTestCase(Derived)
  29. class TestLoadTestsFromTestCaseHook(PluginTester, unittest.TestCase):
  30. activate = '-v'
  31. args = []
  32. plugins = [NoFixturePlug()]
  33. suitepath = os.path.join(support, 'ltftc')
  34. def runTest(self):
  35. expect = [
  36. 'test_value (%s.Derived) ... ERROR' % __name__,
  37. 'test_value (tests.Tests) ... ok']
  38. print str(self.output)
  39. for line in self.output:
  40. if expect:
  41. self.assertEqual(line.strip(), expect.pop(0))
  42. if __name__ == '__main__':
  43. unittest.main()