summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2014-12-21 03:44:52 +0000
committerGerrit Code Review <review@openstack.org>2014-12-21 03:44:52 +0000
commita6bae13407ef129b65a2d1de915e3fc20da70949 (patch)
treefd7d5814d53196ba7b3ea2406f2dad1860e6f948
parentf7ebc8260d235d474a3dc3135608fec216a4b04c (diff)
parent093ed4f9abbc850ef51302e5c569629bb11e2a5b (diff)
downloadoslo-concurrency-a6bae13407ef129b65a2d1de915e3fc20da70949.tar.gz
Merge "Report import warnings where the import occurs"
-rw-r--r--oslo/concurrency/__init__.py2
-rw-r--r--tests/test_warning.py32
2 files changed, 33 insertions, 1 deletions
diff --git a/oslo/concurrency/__init__.py b/oslo/concurrency/__init__.py
index afd4685..b73c33f 100644
--- a/oslo/concurrency/__init__.py
+++ b/oslo/concurrency/__init__.py
@@ -22,7 +22,7 @@ def deprecated():
('The oslo namespace package is deprecated. Please use %s instead.' %
new_name),
DeprecationWarning,
- stacklevel=1,
+ stacklevel=3,
)
diff --git a/tests/test_warning.py b/tests/test_warning.py
index ba1c4df..ec71e0c 100644
--- a/tests/test_warning.py
+++ b/tests/test_warning.py
@@ -11,9 +11,12 @@
# under the License.
import imp
+import os
+import warnings
import mock
from oslotest import base as test_base
+import six
class DeprecationWarningTest(test_base.BaseTestCase):
@@ -27,3 +30,32 @@ class DeprecationWarningTest(test_base.BaseTestCase):
self.assertIn('oslo_concurrency', args[0][0])
self.assertIn('deprecated', args[0][0])
self.assertTrue(issubclass(args[0][1], DeprecationWarning))
+
+ def test_real_warning(self):
+ with warnings.catch_warnings(record=True) as warning_msgs:
+ warnings.resetwarnings()
+ warnings.simplefilter('always', DeprecationWarning)
+ import oslo.concurrency
+
+ # Use a separate function to get the stack level correct
+ # so we know the message points back to this file. This
+ # corresponds to an import or reload, which isn't working
+ # inside the test under Python 3.3. That may be due to a
+ # difference in the import implementation not triggering
+ # warnings properly when the module is reloaded, or
+ # because the warnings module is mostly implemented in C
+ # and something isn't cleanly resetting the global state
+ # used to track whether a warning needs to be
+ # emitted. Whatever the cause, we definitely see the
+ # warnings.warn() being invoked on a reload (see the test
+ # above) and warnings are reported on the console when we
+ # run the tests. A simpler test script run outside of
+ # testr does correctly report the warnings.
+ def foo():
+ oslo.concurrency.deprecated()
+
+ foo()
+ self.assertEqual(1, len(warning_msgs))
+ msg = warning_msgs[0]
+ self.assertIn('oslo_concurrency', six.text_type(msg.message))
+ self.assertEqual('test_warning.py', os.path.basename(msg.filename))