summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-01-05 13:05:26 +0000
committerGerrit Code Review <review@openstack.org>2015-01-05 13:05:26 +0000
commitd0c13d2a13c612b758d8da3b6543828d5d8b07f7 (patch)
tree7e42101ee6a8736617ece2000e69aaec86839cf0
parent75b402be3b8497d12bd21f8c371b52427931952d (diff)
parent91b0199a4f383dc5090cc8582b2ecc63f90f5c22 (diff)
downloadoslo-db-d0c13d2a13c612b758d8da3b6543828d5d8b07f7.tar.gz
Merge "Fix PatchStacktraceTest test"
-rw-r--r--oslo_db/tests/old_import_api/sqlalchemy/test_sqlalchemy.py37
-rw-r--r--oslo_db/tests/sqlalchemy/test_sqlalchemy.py37
2 files changed, 45 insertions, 29 deletions
diff --git a/oslo_db/tests/old_import_api/sqlalchemy/test_sqlalchemy.py b/oslo_db/tests/old_import_api/sqlalchemy/test_sqlalchemy.py
index 8d45cd4..2c80430 100644
--- a/oslo_db/tests/old_import_api/sqlalchemy/test_sqlalchemy.py
+++ b/oslo_db/tests/old_import_api/sqlalchemy/test_sqlalchemy.py
@@ -533,22 +533,31 @@ class MysqlConnectTest(test_base.MySQLOpportunisticTestCase):
log.output)
-# NOTE(dhellmann): This test no longer works as written. The code in
-# oslo_db.sqlalchemy.session filters out lines from modules under
-# oslo_db, and now this test is under oslo_db, so the test filename
-# does not appear in the context for the error message. LP #1405376
+class PatchStacktraceTest(test_base.DbTestCase):
-# class PatchStacktraceTest(test_base.DbTestCase):
+ def test_trace(self):
+ engine = self.engine
-# def test_trace(self):
-# engine = self.engine
-# private_session._add_trace_comments(engine)
-# conn = engine.connect()
-# with mock.patch.object(engine.dialect, "do_execute") as mock_exec:
+ # NOTE(viktors): The code in oslo_db.sqlalchemy.session filters out
+ # lines from modules under oslo_db, so we should remove
+ # "oslo_db/" from file path in traceback.
+ import traceback
+ orig_extract_stack = traceback.extract_stack
-# conn.execute("select * from table")
+ def extract_stack():
+ return [(row[0].replace("oslo_db/", ""), row[1], row[2], row[3])
+ for row in orig_extract_stack()]
-# call = mock_exec.mock_calls[0]
+ with mock.patch("traceback.extract_stack", side_effect=extract_stack):
-# # we're the caller, see that we're in there
-# self.assertTrue("tests/sqlalchemy/test_sqlalchemy.py" in call[1][1])
+ private_session._add_trace_comments(engine)
+ conn = engine.connect()
+ with mock.patch.object(engine.dialect, "do_execute") as mock_exec:
+
+ conn.execute("select * from table")
+
+ call = mock_exec.mock_calls[0]
+
+ # we're the caller, see that we're in there
+ self.assertIn("tests/old_import_api/sqlalchemy/test_sqlalchemy.py",
+ call[1][1])
diff --git a/oslo_db/tests/sqlalchemy/test_sqlalchemy.py b/oslo_db/tests/sqlalchemy/test_sqlalchemy.py
index 84cbbcf..26cda61 100644
--- a/oslo_db/tests/sqlalchemy/test_sqlalchemy.py
+++ b/oslo_db/tests/sqlalchemy/test_sqlalchemy.py
@@ -633,23 +633,30 @@ class CreateEngineTest(oslo_test.BaseTestCase):
)
-# NOTE(dhellmann): This test no longer works as written. The code in
-# oslo_db.sqlalchemy.session filters out lines from modules under
-# oslo_db, and now this test is under oslo_db, so the test filename
-# does not appear in the context for the error message. LP #1405376
+class PatchStacktraceTest(test_base.DbTestCase):
-# class PatchStacktraceTest(test_base.DbTestCase):
+ def test_trace(self):
+ engine = self.engine
-# def test_trace(self):
-# engine = self.engine
-# session._add_trace_comments(engine)
-# conn = engine.connect()
-# with mock.patch.object(engine.dialect, "do_execute") as mock_exec:
+ # NOTE(viktors): The code in oslo_db.sqlalchemy.session filters out
+ # lines from modules under oslo_db, so we should remove
+ # "oslo_db/" from file path in traceback.
+ import traceback
+ orig_extract_stack = traceback.extract_stack
-# conn.execute("select * from table")
+ def extract_stack():
+ return [(row[0].replace("oslo_db/", ""), row[1], row[2], row[3])
+ for row in orig_extract_stack()]
-# call = mock_exec.mock_calls[0]
+ with mock.patch("traceback.extract_stack", side_effect=extract_stack):
-# # we're the caller, see that we're in there
-# self.assertIn("oslo_db/tests/sqlalchemy/test_sqlalchemy.py",
-# call[1][1])
+ session._add_trace_comments(engine)
+ conn = engine.connect()
+ with mock.patch.object(engine.dialect, "do_execute") as mock_exec:
+
+ conn.execute("select * from table")
+
+ call = mock_exec.mock_calls[0]
+
+ # we're the caller, see that we're in there
+ self.assertIn("tests/sqlalchemy/test_sqlalchemy.py", call[1][1])