【发布时间】:2018-07-11 02:54:20
【问题描述】:
我的以下代码在作为 python unittest 运行时可以正常工作,但如果使用带有以下错误消息的 nosetest 或 py.test 则会失败:
鼻子测试错误: PicklingError: Can't pickle : it's not found as teamcity.nose_report.newCaptureBeforeTest
py.test 错误: PicklingError: Can't pickle : it's not found as __builtin__.module
代码:
import unittest
import multiprocessing as mp
import time
TIME_LIMIT = 1
class TestCases(unittest.TestCase):
def setUp(self):
self.a = 0
def my_func(self):
time.sleep(2)
self.q.put(self.a + 1)
def run_case(self, func):
self.q = mp.Queue()
test_process = mp.Process(target=func)
test_process.start()
test_process.join(TIME_LIMIT)
self.assertFalse(test_process.is_alive(), 'timeout exceeded')
def test_case1(self):
self.run_case(self.my_func)
self.assertEquals(self.a + 1, self.q.get())
【问题讨论】:
标签: python-2.7 pytest python-multiprocessing nose