/unit_tests/test_multiprocess.py

https://bitbucket.org/jpellerin/nose/ · Python · 62 lines · 48 code · 9 blank · 5 comment · 4 complexity · f66cdc09a93a4e59ba69ee3445116689 MD5 · raw file

  1. import pickle
  2. import sys
  3. import unittest
  4. from nose import case
  5. from nose.plugins import multiprocess
  6. from nose.plugins.skip import SkipTest
  7. from nose.config import Config
  8. from nose.loader import TestLoader
  9. try:
  10. # 2.7+
  11. from unittest.runner import _WritelnDecorator
  12. except ImportError:
  13. from unittest import _WritelnDecorator
  14. class ArgChecker:
  15. def __init__(self, target, args):
  16. self.target = target
  17. self.args = args
  18. # skip the id and queues
  19. pargs = args[7:]
  20. self.pickled = pickle.dumps(pargs)
  21. try:
  22. testQueue = args[1]
  23. testQueue.get(timeout=0)
  24. except:
  25. pass # ok if queue is empty
  26. def start(self,*args):
  27. pass
  28. def is_alive(self):
  29. return False
  30. def setup(mod):
  31. multiprocess._import_mp()
  32. if not multiprocess.Process:
  33. raise SkipTest("multiprocessing not available")
  34. mod.Process = multiprocess.Process
  35. multiprocess.Process = ArgChecker
  36. class T(unittest.TestCase):
  37. __test__ = False
  38. def runTest(self):
  39. pass
  40. def test_mp_process_args_pickleable():
  41. # TODO(Kumar) this test needs to be more succint.
  42. # If you start seeing it timeout then perhaps we need to skip it again.
  43. # raise SkipTest('this currently gets stuck in poll() 90% of the time')
  44. test = case.Test(T('runTest'))
  45. config = Config()
  46. config.multiprocess_workers = 2
  47. config.multiprocess_timeout = 5
  48. runner = multiprocess.MultiProcessTestRunner(
  49. stream=_WritelnDecorator(sys.stdout),
  50. verbosity=10,
  51. loaderClass=TestLoader,
  52. config=config)
  53. runner.run(test)