Change-Id: Icda200b7f1d17e9d5cde2a2438df9cfdca0b48a5
3.5 KiB
Refactor Test Base Class in oslotest
Include the URL of your launchpad blueprint:
https://blueprints.launchpad.net/oslo?searchtext=oslotest-refactor
As a general policy we want to avoid requiring projects to use test base classes defined in libraries they do not control. Test fixtures are more composable, and easier to test themselves.
Problem description
Copied from /specs/policy/test-tools
:
We originally created oslotest as a place to include the base class for all unit tests across all projects, to give the projects common behaviors in their test suites. Using a common base class is not always possible, however, when applications want to use their own base class and test fixture classes in ways that do not mix well. Multiple inheritance, in particular, is a problem because the order of setup and tear-down for test cases is harder to reason about.
Proposed change
- Provide a fixture to change the
maxDiff
attribute of a test case, with a default of 10,000 as in BaseTestCase. - Provide a fixture to wrap
fixtures.Timeout
using an environment variable to set the actual timeout, based on :pyBaseTestCase._set_timeout
. - Provide a fixture to mock stdout and stderr, based on :py
BaseTestCase._fake_output
. - Provide a fixture to wrap
fixtures.FakeLogger
using an environment variable to set the actual timeout, based on :pyBaseTestCase._fake_logs
. - Provide a fixture to create a temporary file with content to
replicate the features of :py
BaseTestCase.create_tempfiles
. We should use one fixture per file, and provide the full path to the resulting file as an attribute of the fixture. - Add
DeprecationWarning
to :pyBaseTestCase.setUp
.
Alternatives
Leave Everything Alone
Leaving BaseTestCase
alone risks making it completely
obsolete as projects drop its use due to issues with multiple
inheritance.
Impact on Existing APIs
The existing DeprecationWarning
will not be changed other than to
add the deprecation warning, so all existing users will continue to be
able to use it until they move to the new fixtures.
Security impact
None
Performance Impact
None
Configuration Impact
None
Developer Impact
Developers will need to create or update their own test base classes to use the desired fixtures. The old test case will not be removed for at least one cycle, to allow for migration time.
Testing Impact
We will need unit tests for the new fixtures.
Implementation
Assignee(s)
- Primary assignee:
-
Doug Hellmann
Milestones
Target Milestone for completion: Liberty-2
Work Items
See "Proposed change" above.
Incubation
N/A
Adoption
N/A
Library
N/A
Anticipated API Stabilization
N/A
Documentation Impact
Each change will require updates to the API documentation for oslotest.
Dependencies
/specs/policy/test-tools
References
/specs/policy/test-tools
Note
This work is licensed under a Creative Commons Attribution 3.0 Unported License. http://creativecommons.org/licenses/by/3.0/legalcode