fixture

class oslo_service.fixture.SleepFixture

基础: Fixture

一个用于模拟 loopingcall 事件中的 wait() 的 fixture。

这使得测试用例能够在不实际产生睡眠的墙钟时间的情况下,测试使用 loopingcall 的代码。

wait() 的模拟可以通过 fixture 的 mock_wait 属性访问。

注意

不建议断言模拟的特定参数(例如,超时值),因为这依赖于 loopingcall 的内部结构不发生变化。

示例用法

from oslo.service import fixture
...
class MyTest(...):
    def setUp(self):
        ...
        self.sleepfx = self.useFixture(fixture.SleepFixture())
        ...

    def test_this(self):
        ...
        thing_that_hits_a_loopingcall()
        ...
        self.assertEqual(5, self.sleepfx.mock_wait.call_count)
        ...