-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: Add tests for CTX manager usage on PEP0249. #448
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a TC where the db is not managed, but the cursor is.
Please cover the rest of the instrumentations where PEP0248 is used, like mysql.
Add the test_connect_ctx_mngr UT to test the span creation when using the psycopg2 connect with context manager, and the test_connect_cursor_ctx_mngr UT when using the psycopg2 connect and cursos context manager. Signed-off-by: Paulo Vital <[email protected]>
f67eabc
to
ccf7ce0
Compare
I am closing this PR once we use #450 to track this fix. |
self.assertEqual(test_span.t, db_span.t) | ||
self.assertEqual(db_span.p, test_span.s) | ||
|
||
self.assertEqual(None, db_span.ec) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be assertIsNone
self.assertEqual(test_span.t, db_span.t) | ||
self.assertEqual(db_span.p, test_span.s) | ||
|
||
self.assertEqual(None, db_span.ec) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be assertIsNone
self.assertEqual(test_span.t, db_span.t) | ||
self.assertEqual(db_span.p, test_span.s) | ||
|
||
self.assertEqual(None, db_span.ec) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be assertIsNone
self.assertEqual(test_span.t, db_span.t) | ||
self.assertEqual(db_span.p, test_span.s) | ||
|
||
self.assertEqual(None, db_span.ec) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be assertIsNone
self.assertEqual(test_span.t, db_span.t) | ||
self.assertEqual(db_span.p, test_span.s) | ||
|
||
self.assertEqual(None, db_span.ec) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be assertIsNone
self.assertEqual(test_span.t, db_span.t) | ||
self.assertEqual(db_span.p, test_span.s) | ||
|
||
self.assertEqual(None, db_span.ec) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be assertIsNone
self.assertEqual(test_span.t, db_span.t) | ||
self.assertEqual(db_span.p, test_span.s) | ||
|
||
self.assertEqual(None, db_span.ec) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be assertIsNone
self.assertEqual(test_span.t, db_span.t) | ||
self.assertEqual(db_span.p, test_span.s) | ||
|
||
self.assertEqual(None, db_span.ec) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be assertIsNone
self.assertEqual(test_span.t, db_span.t) | ||
self.assertEqual(db_span.p, test_span.s) | ||
|
||
self.assertEqual(None, db_span.ec) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be assertIsNone
result = cursor.execute("""SELECT * from users""") | ||
cursor.fetchone() | ||
|
||
assert(result >= 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assert
is for catching runtime anomalies in the production code, after it is deployed.
For unit testing we should use assertTrue, if nothing else fits better.
result = cursor.execute("""SELECT * from users""") | ||
cursor.fetchone() | ||
|
||
assert(result >= 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assert
is for catching runtime anomalies in the production code, after it is deployed.
For unit testing we should use assertTrue, if nothing else fits better.
cursor.fetchone() | ||
self.db.close() | ||
|
||
assert(result >= 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assert
is for catching runtime anomalies in the production code, after it is deployed.
For unit testing we should use assertTrue, if nothing else fits better.
result = cursor.execute("""SELECT * from users""") | ||
cursor.fetchone() | ||
|
||
assert(result >= 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assert
is for catching runtime anomalies in the production code, after it is deployed.
For unit testing we should use assertTrue, if nothing else fits better.
cursor.fetchone() | ||
self.db.close() | ||
|
||
assert(result >= 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assert
is for catching runtime anomalies in the production code, after it is deployed.
For unit testing we should use assertTrue, if nothing else fits better.
result = cursor.execute("""SELECT * from users""") | ||
cursor.fetchone() | ||
|
||
assert(result >= 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assert
is for catching runtime anomalies in the production code, after it is deployed.
For unit testing we should use assertTrue, if nothing else fits better.
@@ -217,3 +217,93 @@ def test_error_capture(self): | |||
self.assertEqual(db_span.data["mysql"]["stmt"], 'SELECT * from blah') | |||
self.assertEqual(db_span.data["mysql"]["host"], testenv['mysql_host']) | |||
self.assertEqual(db_span.data["mysql"]["port"], testenv['mysql_port']) | |||
|
|||
def test_connect_ctx_mngr(self): | |||
result = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The context manager does not create a new scope, the result = cursor.execute(
statement is enough. Please remove this line, luckily this is not Pascal or ANSI C, where you have to declare the variables way ahead of assigning them.
self.assertEqual(db_span.data["mysql"]["port"], testenv['mysql_port']) | ||
|
||
def test_cursor_ctx_mngr(self): | ||
result = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove.
self.assertEqual(db_span.data["mysql"]["port"], testenv['mysql_port']) | ||
|
||
def test_connect_cursor_ctx_mngr(self): | ||
result = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove.
@@ -243,3 +243,93 @@ def test_error_capture(self): | |||
self.assertEqual(db_span.data["mysql"]["stmt"], 'SELECT * from blah') | |||
self.assertEqual(db_span.data["mysql"]["host"], testenv['mysql_host']) | |||
self.assertEqual(db_span.data["mysql"]["port"], testenv['mysql_port']) | |||
|
|||
def test_connect_ctx_mngr(self): | |||
result = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove.
self.assertEqual(db_span.data["mysql"]["port"], testenv['mysql_port']) | ||
|
||
def test_cursor_ctx_mngr(self): | ||
result = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove.
self.assertEqual(db_span.data["mysql"]["port"], testenv['mysql_port']) | ||
|
||
def test_connect_cursor_ctx_mngr(self): | ||
result = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a preliminary review. With some minor formalities commented for now.
Add the test_connect_ctx_mngr UT to test the span creation when using the psycopg2 connect with context manager, and the test_connect_cursor_ctx_mngr UT when using the psycopg2 connect and cursos context manager.