/unit_tests/test_multiprocess_runner.py

https://bitbucket.org/jpellerin/nose/ · Python · 120 lines · 93 code · 27 blank · 0 comment · 3 complexity · 5139f7a589aca0866e35ff9985c7fbc8 MD5 · raw file

  1. import unittest
  2. import imp
  3. import sys
  4. from nose.loader import TestLoader
  5. from nose.plugins import multiprocess
  6. from nose.suite import ContextSuite
  7. class T_fixt:
  8. def setupClass(cls):
  9. pass
  10. setupClass = classmethod(setupClass)
  11. def test_a(self):
  12. pass
  13. def test_b(self):
  14. pass
  15. class T:
  16. def test_a(self):
  17. pass
  18. def test_b(self):
  19. pass
  20. class TestMultiProcessTestRunner(unittest.TestCase):
  21. def test_next_batch_with_classes(self):
  22. r = multiprocess.MultiProcessTestRunner()
  23. l = TestLoader()
  24. tests = list(r.nextBatch(ContextSuite(
  25. tests=[l.makeTest(T_fixt), l.makeTest(T)])))
  26. print tests
  27. self.assertEqual(len(tests), 3)
  28. def test_next_batch_with_module_fixt(self):
  29. mod_with_fixt = imp.new_module('mod_with_fixt')
  30. sys.modules['mod_with_fixt'] = mod_with_fixt
  31. def teardown():
  32. pass
  33. class Test(T):
  34. pass
  35. mod_with_fixt.Test = Test
  36. mod_with_fixt.teardown = teardown
  37. Test.__module__ = 'mod_with_fixt'
  38. r = multiprocess.MultiProcessTestRunner()
  39. l = TestLoader()
  40. tests = list(r.nextBatch(l.loadTestsFromModule(mod_with_fixt)))
  41. print tests
  42. self.assertEqual(len(tests), 1)
  43. def test_next_batch_with_module(self):
  44. mod_no_fixt = imp.new_module('mod_no_fixt')
  45. sys.modules['mod_no_fixt'] = mod_no_fixt
  46. class Test2(T):
  47. pass
  48. class Test_fixt(T_fixt):
  49. pass
  50. mod_no_fixt.Test = Test2
  51. Test2.__module__ = 'mod_no_fixt'
  52. mod_no_fixt.Test_fixt = Test_fixt
  53. Test_fixt.__module__ = 'mod_no_fixt'
  54. r = multiprocess.MultiProcessTestRunner()
  55. l = TestLoader()
  56. tests = list(r.nextBatch(l.loadTestsFromModule(mod_no_fixt)))
  57. print tests
  58. self.assertEqual(len(tests), 3)
  59. def test_next_batch_with_generator_method(self):
  60. class Tg:
  61. def test_gen(self):
  62. for i in range(0, 3):
  63. yield self.check, i
  64. def check(self, val):
  65. pass
  66. r = multiprocess.MultiProcessTestRunner()
  67. l = TestLoader()
  68. tests = list(r.nextBatch(l.makeTest(Tg)))
  69. print tests
  70. print [r.address(t) for t in tests]
  71. self.assertEqual(len(tests), 1)
  72. def test_next_batch_can_split_set(self):
  73. mod_with_fixt2 = imp.new_module('mod_with_fixt2')
  74. sys.modules['mod_with_fixt2'] = mod_with_fixt2
  75. def setup():
  76. pass
  77. class Test(T):
  78. pass
  79. class Test_fixt(T_fixt):
  80. pass
  81. mod_with_fixt2.Test = Test
  82. mod_with_fixt2.Test_fixt = Test_fixt
  83. mod_with_fixt2.setup = setup
  84. mod_with_fixt2._multiprocess_can_split_ = True
  85. Test.__module__ = 'mod_with_fixt2'
  86. Test_fixt.__module__ = 'mod_with_fixt2'
  87. r = multiprocess.MultiProcessTestRunner()
  88. l = TestLoader()
  89. tests = list(r.nextBatch(l.loadTestsFromModule(mod_with_fixt2)))
  90. print tests
  91. self.assertEqual(len(tests), 3)
  92. if __name__ == '__main__':
  93. unittest.main()