PageRenderTime 11ms CodeModel.GetById 1ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/unit_tests/test_multiprocess.py

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