Deprecations fixture support calling deprecated function
Sometimes a test is expected to call deprecated function, such as when testing that deprecated function still works. Now the test can tell the Deprecations fixture that it's calling deprecated function. Change-Id: Ic7486b74f681989eb5110dfeaf8dae0e5d7ae50e
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import contextlib
|
||||||
import os
|
import os
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
@@ -607,3 +608,14 @@ class Deprecations(fixtures.Fixture):
|
|||||||
warnings.filterwarnings('error', category=DeprecationWarning,
|
warnings.filterwarnings('error', category=DeprecationWarning,
|
||||||
module='^keystoneclient\\.')
|
module='^keystoneclient\\.')
|
||||||
self.addCleanup(warnings.resetwarnings)
|
self.addCleanup(warnings.resetwarnings)
|
||||||
|
|
||||||
|
def expect_deprecations(self):
|
||||||
|
"""Call this if the test expects to call deprecated function."""
|
||||||
|
warnings.resetwarnings()
|
||||||
|
|
||||||
|
@contextlib.contextmanager
|
||||||
|
def expect_deprecations_here(self):
|
||||||
|
warnings.resetwarnings()
|
||||||
|
yield
|
||||||
|
warnings.filterwarnings('error', category=DeprecationWarning,
|
||||||
|
module='^keystoneclient\\.')
|
||||||
|
@@ -42,7 +42,7 @@ class TestCase(testtools.TestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestCase, self).setUp()
|
super(TestCase, self).setUp()
|
||||||
self.useFixture(client_fixtures.Deprecations())
|
self.deprecations = self.useFixture(client_fixtures.Deprecations())
|
||||||
|
|
||||||
self.logger = self.useFixture(fixtures.FakeLogger(level=logging.DEBUG))
|
self.logger = self.useFixture(fixtures.FakeLogger(level=logging.DEBUG))
|
||||||
self.requests_mock = self.useFixture(fixture.Fixture())
|
self.requests_mock = self.useFixture(fixture.Fixture())
|
||||||
|
Reference in New Issue
Block a user