diff options
author | Victor Sergeyev <vsergeyev@mirantis.com> | 2014-12-25 19:14:11 +0200 |
---|---|---|
committer | Roman Podoliaka <rpodolyaka@mirantis.com> | 2015-01-05 09:31:48 +0000 |
commit | 91b0199a4f383dc5090cc8582b2ecc63f90f5c22 (patch) | |
tree | e301ca815a2a2cb7de77622d9263f06bb0a8d324 | |
parent | 44c9c574bda9ef25b19ab619e1ea66ef2b125101 (diff) | |
download | oslo-db-91b0199a4f383dc5090cc8582b2ecc63f90f5c22.tar.gz |
Fix PatchStacktraceTest test
After we moved out from the namespaces, tests were moved to
oslo_db/tests. The code in oslo_db.sqlalchemy.session filters out
lines from modules under oslo_db, so the test filename does not
appear in the context for the error message.
Use patched traceback module in tests to fix it.
Closes-Bug: #1405376
Change-Id: Id6022c065dfe13351fca5e54baa343d6c96b0270
-rw-r--r-- | oslo_db/tests/old_import_api/sqlalchemy/test_sqlalchemy.py | 37 | ||||
-rw-r--r-- | oslo_db/tests/sqlalchemy/test_sqlalchemy.py | 37 |
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]) |