Oslo Test Framework
raw JSON → 6.1.1 verified Fri May 01 auth: no python
Oslo test framework provides test utilities and base test classes for OpenStack projects. It helps with test isolation, mocking configuration, and fixture management. Current version: 6.1.1, release cadence is seasonal (aligned with OpenStack releases).
pip install oslotest Common errors
error ImportError: cannot import name 'BaseTestCase' from 'oslotest' ↓
cause Incorrect import path. In older versions of oslotest (pre 1.0?), BaseTestCase was at oslotest.base.BaseTestCase, but in current oslotest, BaseTestCase is re-exported via testtools and available via `from oslotest import base` then `base.BaseTestCase`.
fix
Use
from oslotest import base then base.BaseTestCase. error AttributeError: module 'oslotest' has no attribute 'fake' ↓
cause The fake module was deprecated and removed in oslotest 5.0+.
fix
Use
unittest.mock module instead of oslotest.fake. Warnings
gotcha Using `oslotest.base.BaseTestCase` directly (instead of through the `base` submodule) is not recommended. The class is re-exported from testtools, and direct imports may break in future versions. ↓
fix Use `from oslotest import base` and access `base.BaseTestCase`.
deprecated `oslotest.fake` module is deprecated and may be removed in future versions. Use `unittest.mock` or fixtures instead. ↓
fix Replace `from oslotest import fake` with `from unittest.mock import Mock` or appropriate mocking.
gotcha The `oslotest` package is primarily for OpenStack internal testing. External projects may find it heavy and tied to OpenStack conventions (e.g., configuration files). ↓
fix Consider lighter alternatives like `pytest` or `fixtures` directly if you don't need OpenStack integration.
Imports
- BaseTestCase wrong
from oslotest.base import BaseTestCasecorrectfrom oslotest import base - create_service_fixture wrong
from oslotest.fixture import create_service_fixturecorrectfrom oslotest import create_service_fixture
Quickstart
import os
from oslotest import base
class MyTestCase(base.BaseTestCase):
def setUp(self):
super(MyTestCase, self).setUp()
# Use fixtures to set up temp files or env vars
self.useFixture(base.NestedTempfile())
def test_something(self):
result = some_function()
self.assertEqual(result, expected)
# For running: python -m testtools.run discover