summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrant Knudson <bknudson@us.ibm.com>2015-07-24 08:05:13 -0500
committerBrant Knudson <bknudson@us.ibm.com>2015-07-24 08:05:13 -0500
commit610844d06db5b2af93c0747a7690c44d3724510b (patch)
treefc9edce1f8d5ca7f3847e63189a50bd62292525d
parent43749c5ac1372ad4bce7a2a0fa0f677c478e7545 (diff)
downloadpython-keystoneclient-610844d06db5b2af93c0747a7690c44d3724510b.tar.gz
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
-rw-r--r--keystoneclient/tests/unit/client_fixtures.py12
-rw-r--r--keystoneclient/tests/unit/utils.py2
2 files changed, 13 insertions, 1 deletions
diff --git a/keystoneclient/tests/unit/client_fixtures.py b/keystoneclient/tests/unit/client_fixtures.py
index dfb2b21..46266ce 100644
--- a/keystoneclient/tests/unit/client_fixtures.py
+++ b/keystoneclient/tests/unit/client_fixtures.py
@@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
+import contextlib
import os
import warnings
@@ -607,3 +608,14 @@ class Deprecations(fixtures.Fixture):
warnings.filterwarnings('error', category=DeprecationWarning,
module='^keystoneclient\\.')
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\\.')
diff --git a/keystoneclient/tests/unit/utils.py b/keystoneclient/tests/unit/utils.py
index d865e68..7c6de95 100644
--- a/keystoneclient/tests/unit/utils.py
+++ b/keystoneclient/tests/unit/utils.py
@@ -42,7 +42,7 @@ class TestCase(testtools.TestCase):
def setUp(self):
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.requests_mock = self.useFixture(fixture.Fixture())