tests(bigquery): harden system test teardown and unit test auth isolation - #17964
tests(bigquery): harden system test teardown and unit test auth isolation#17964shuoweil wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates system and unit tests for the BigQuery client and magics. Key changes include catching NotFound exceptions during tag deletion in system tests, switching to IPython.core.interactiveshell, making the local magics context fixture run automatically, and refactoring several tests to use parenthesized context managers. The review feedback highlights that parenthesized context managers will cause a SyntaxError in Python 3.8 environments, which are still supported by this package. Additionally, the reviewer noted that manually resetting credentials in test_context_with_default_credentials is redundant due to the updated autouse fixture, and suggested renaming test_context_fallback_when_bigquery_magics_none to better describe its purpose.
| with ( | ||
| run_query_patch as run_query_mock, | ||
| bqstorage_client_patch, | ||
| warnings.catch_warnings(record=True) as warned, | ||
| ): |
There was a problem hiding this comment.
Using parenthesized context managers (e.g., with (A, B):) is a feature introduced in Python 3.9. Since this package supports Python 3.8, using this syntax will result in a SyntaxError on Python 3.8 environments. To maintain backwards compatibility, please use standard line continuation with backslashes.
with run_query_patch as run_query_mock, \
bqstorage_client_patch, \
warnings.catch_warnings(record=True) as warned:| with ( | ||
| pytest.raises(OSError), | ||
| client_query_patch as client_query_mock, | ||
| default_patch, | ||
| close_transports_patch as close_transports, | ||
| ): |
There was a problem hiding this comment.
Using parenthesized context managers (e.g., with (A, B):) is a feature introduced in Python 3.9. Since this package supports Python 3.8, using this syntax will result in a SyntaxError on Python 3.8 environments. To maintain backwards compatibility, please use standard line continuation with backslashes.
with pytest.raises(OSError), \
client_query_patch as client_query_mock, \
default_patch, \
close_transports_patch as close_transports:| with ( | ||
| pytest.raises(NameError, match=r".*custom_query does not exist.*"), | ||
| run_query_patch as run_query_mock, | ||
| ): |
There was a problem hiding this comment.
Using parenthesized context managers (e.g., with (A, B):) is a feature introduced in Python 3.9. Since this package supports Python 3.8, using this syntax will result in a SyntaxError on Python 3.8 environments. To maintain backwards compatibility, please use standard line continuation with backslashes.
with pytest.raises(NameError, match=r".*custom_query does not exist.*"), \
run_query_patch as run_query_mock:| with ( | ||
| pytest.raises(NameError, match=r"(?i).*missing query variable name.*"), | ||
| run_query_patch as run_query_mock, | ||
| ): |
There was a problem hiding this comment.
Using parenthesized context managers (e.g., with (A, B):) is a feature introduced in Python 3.9. Since this package supports Python 3.8, using this syntax will result in a SyntaxError on Python 3.8 environments. To maintain backwards compatibility, please use standard line continuation with backslashes.
with pytest.raises(NameError, match=r"(?i).*missing query variable name.*"), \
run_query_patch as run_query_mock:| with ( | ||
| pytest.raises(TypeError, match=r".*must be a string or a bytes-like.*"), | ||
| run_query_patch as run_query_mock, | ||
| ): |
There was a problem hiding this comment.
Using parenthesized context managers (e.g., with (A, B):) is a feature introduced in Python 3.9. Since this package supports Python 3.8, using this syntax will result in a SyntaxError on Python 3.8 environments. To maintain backwards compatibility, please use standard line continuation with backslashes.
with pytest.raises(TypeError, match=r".*must be a string or a bytes-like.*"), \
run_query_patch as run_query_mock:| with ( | ||
| pytest.raises(OSError), | ||
| create_dataset_if_necessary_patch, | ||
| close_transports_patch as close_transports, | ||
| ): |
There was a problem hiding this comment.
Using parenthesized context managers (e.g., with (A, B):) is a feature introduced in Python 3.9. Since this package supports Python 3.8, using this syntax will result in a SyntaxError on Python 3.8 environments. To maintain backwards compatibility, please use standard line continuation with backslashes.
with pytest.raises(OSError), \
create_dataset_if_necessary_patch, \
close_transports_patch as close_transports:Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Following the merge of PR #17953 for the socket leak fix, this PR focuses on the remaining orthogonal test and fixture hardening fixes:
try...except NotFound: passduringTestBigQuery.tearDown()to prevent cascaded teardown failures when tag resources were already deleted.autouse=Trueon theuse_local_magics_contextfixture intest_magics.pyto prevent credentials mutation across test runs in uncredentialed CI environments.IPython.core.interactiveshell.InteractiveShelland add fallback unit test coverage formagics.Context.Related: b/540939659 🦕