fixture

class oslo_service.fixture.SleepFixture

Bases: Fixture

A fixture for mocking the sleep within loopingcall loops.

This exists so test cases can exercise code that uses loopingcall without actually incurring wall clock time for sleeping.

The sleep mock is accessible via the fixture’s mock_wait attribute. It works with both the eventlet and threading backends.

Note

It is not recommended to assert specific arguments (i.e. timeout values) to the mock, as this relies on the internals of loopingcall not changing.

Example usage:

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)
        ...