Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Multithreading 使unittest等待任务完成_Multithreading_Python 2.7_Unit Testing_Sleep_Python Unittest - Fatal编程技术网

Multithreading 使unittest等待任务完成

Multithreading 使unittest等待任务完成,multithreading,python-2.7,unit-testing,sleep,python-unittest,Multithreading,Python 2.7,Unit Testing,Sleep,Python Unittest,我正在为定时进程进行单元测试,在我的测试中,有些情况依赖于定时操作,例如: class MovementTest(unittest.TestCase): def goto_test(self): self.robot.goto(3, 4, 10) # go to x=3, y=4 in 10 seconds # wait the 10 seconds # the objective of the test is that the robot is able to g

我正在为定时进程进行单元测试,在我的测试中,有些情况依赖于定时操作,例如:

class MovementTest(unittest.TestCase):
  def goto_test(self):
    self.robot.goto(3, 4, 10)  # go to x=3, y=4 in 10 seconds
    # wait the 10 seconds
    # the objective of the test is that the robot is able to get to (3, 4) in
    # 10 seconds, that's why I need the waiting
    self.assertEqual(self.robot.position, (3, 4))
问题是,当我使用time.sleep(10)时,程序没有等待,因此测试失败。是否有一种方法可以让unittest等待这个测试用例所需的时间,如果在等待过程中可以运行一些其他测试也会很好


我尝试使用线程,但结果是测试检查完成,测试程序等待,但断言未检查。

仅供记录:我会研究在进行单元测试时改变“时间”概念的方法。您绝对不希望单元测试花费的时间超过几秒钟;让单元测试坐在那里等待生产代码中的某些内容10秒是一种糟糕的做法。因此,我的第一个目标是在测试设置中操纵测试代码,使其不需要10秒。我同意@GhostCat的观点,请发布测试中的代码,以提供有关您试图解决的问题的更多上下文。