@@ -686,9 +686,11 @@ def test_bigquery_magic_with_bqstorage_from_argument(
686686 google .cloud .bigquery .job .QueryJob , instance = True
687687 )
688688 query_job_mock .to_dataframe .return_value = result
689- with run_query_patch as run_query_mock , (
690- bqstorage_client_patch
691- ), warnings .catch_warnings (record = True ) as warned :
689+ with (
690+ run_query_patch as run_query_mock ,
691+ bqstorage_client_patch ,
692+ warnings .catch_warnings (record = True ) as warned ,
693+ ):
692694 run_query_mock .return_value = query_job_mock
693695
694696 return_value = ip .run_cell_magic ("bigquery" , "--use_bqstorage_api" , sql )
@@ -854,11 +856,12 @@ def test_bigquery_magic_w_max_results_query_job_results_fails(monkeypatch):
854856 )
855857 query_job_mock .result .side_effect = [[], OSError ]
856858
857- with pytest .raises (
858- OSError
859- ), client_query_patch as client_query_mock , (
860- default_patch
861- ), close_transports_patch as close_transports :
859+ with (
860+ pytest .raises (OSError ),
861+ client_query_patch as client_query_mock ,
862+ default_patch ,
863+ close_transports_patch as close_transports ,
864+ ):
862865 client_query_mock .return_value = query_job_mock
863866 ip .run_cell_magic ("bigquery" , "--max_results=5" , sql )
864867
@@ -1977,9 +1980,10 @@ def test_bigquery_magic_nonexisting_query_variable(monkeypatch):
19771980 ip .user_ns .pop ("custom_query" , None ) # Make sure the variable does NOT exist.
19781981 cell_body = "$custom_query" # Referring to a non-existing variable name.
19791982
1980- with pytest .raises (
1981- NameError , match = r".*custom_query does not exist.*"
1982- ), run_query_patch as run_query_mock :
1983+ with (
1984+ pytest .raises (NameError , match = r".*custom_query does not exist.*" ),
1985+ run_query_patch as run_query_mock ,
1986+ ):
19831987 ip .run_cell_magic ("bigquery" , "" , cell_body )
19841988
19851989 run_query_mock .assert_not_called ()
@@ -2000,9 +2004,10 @@ def test_bigquery_magic_empty_query_variable_name(monkeypatch):
20002004 )
20012005 cell_body = "$" # Not referring to any variable (name omitted).
20022006
2003- with pytest .raises (
2004- NameError , match = r"(?i).*missing query variable name.*"
2005- ), run_query_patch as run_query_mock :
2007+ with (
2008+ pytest .raises (NameError , match = r"(?i).*missing query variable name.*" ),
2009+ run_query_patch as run_query_mock ,
2010+ ):
20062011 ip .run_cell_magic ("bigquery" , "" , cell_body )
20072012
20082013 run_query_mock .assert_not_called ()
@@ -2028,9 +2033,10 @@ def test_bigquery_magic_query_variable_non_string(ipython_ns_cleanup, monkeypatc
20282033 ip .user_ns ["custom_query" ] = object ()
20292034 cell_body = "$custom_query" # Referring to a non-string variable.
20302035
2031- with pytest .raises (
2032- TypeError , match = r".*must be a string or a bytes-like.*"
2033- ), run_query_patch as run_query_mock :
2036+ with (
2037+ pytest .raises (TypeError , match = r".*must be a string or a bytes-like.*" ),
2038+ run_query_patch as run_query_mock ,
2039+ ):
20342040 ip .run_cell_magic ("bigquery" , "" , cell_body )
20352041
20362042 run_query_mock .assert_not_called ()
@@ -2195,9 +2201,11 @@ def test_bigquery_magic_create_dataset_fails(monkeypatch):
21952201 autospec = True ,
21962202 )
21972203
2198- with pytest .raises (
2199- OSError
2200- ), create_dataset_if_necessary_patch , close_transports_patch as close_transports :
2204+ with (
2205+ pytest .raises (OSError ),
2206+ create_dataset_if_necessary_patch ,
2207+ close_transports_patch as close_transports ,
2208+ ):
22012209 ip .run_cell_magic (
22022210 "bigquery" ,
22032211 "--destination_table dataset_id.table_id" ,
0 commit comments