@@ -480,6 +480,7 @@ def test_bigquery_magic_without_optional_arguments(monkeypatch):
480480 run_query_patch = mock .patch (
481481 "google.cloud.bigquery.magics.magics._run_query" , autospec = True
482482 )
483+ magics .context .project = "unit-test-project"
483484 query_job_mock = mock .create_autospec (
484485 google .cloud .bigquery .job .QueryJob , instance = True
485486 )
@@ -831,6 +832,7 @@ def test_bigquery_magic_w_max_results_query_job_results_fails(monkeypatch):
831832 assert close_transports .called
832833
833834
835+ @pytest .mark .usefixtures ("ipython_interactive" )
834836def test_bigquery_magic_w_table_id_invalid (monkeypatch ):
835837 ip = IPython .get_ipython ()
836838 monkeypatch .setattr (bigquery , "bigquery_magics" , None )
@@ -861,6 +863,7 @@ def test_bigquery_magic_w_table_id_invalid(monkeypatch):
861863 assert "Traceback (most recent call last)" not in output
862864
863865
866+ @pytest .mark .usefixtures ("ipython_interactive" )
864867def test_bigquery_magic_w_missing_query (monkeypatch ):
865868 ip = IPython .get_ipython ()
866869 monkeypatch .setattr (bigquery , "bigquery_magics" , None )
@@ -1354,6 +1357,8 @@ def test_bigquery_magic_w_progress_bar_type_w_context_setter(monkeypatch):
13541357 run_query_patch = mock .patch (
13551358 "google.cloud.bigquery.magics.magics._run_query" , autospec = True
13561359 )
1360+ magics .context .project = "unit-test-project"
1361+
13571362 query_job_mock = mock .create_autospec (
13581363 google .cloud .bigquery .job .QueryJob , instance = True
13591364 )
@@ -1383,6 +1388,8 @@ def test_bigquery_magic_with_progress_bar_type(monkeypatch):
13831388 run_query_patch = mock .patch (
13841389 "google.cloud.bigquery.magics.magics._run_query" , autospec = True
13851390 )
1391+ magics .context .project = "unit-test-project"
1392+
13861393 with run_query_patch as run_query_mock :
13871394 ip .run_cell_magic (
13881395 "bigquery" , "--progress_bar_type=tqdm_gui" , "SELECT 17 as num"
@@ -1565,6 +1572,8 @@ def test_bigquery_magic_with_string_params(ipython_ns_cleanup, monkeypatch):
15651572 run_query_patch = mock .patch (
15661573 "google.cloud.bigquery.magics.magics._run_query" , autospec = True
15671574 )
1575+ magics .context .project = "unit-test-project"
1576+
15681577 query_job_mock = mock .create_autospec (
15691578 google .cloud .bigquery .job .QueryJob , instance = True
15701579 )
@@ -1605,6 +1614,8 @@ def test_bigquery_magic_with_dict_params(ipython_ns_cleanup, monkeypatch):
16051614 run_query_patch = mock .patch (
16061615 "google.cloud.bigquery.magics.magics._run_query" , autospec = True
16071616 )
1617+ magics .context .project = "unit-test-project"
1618+
16081619 query_job_mock = mock .create_autospec (
16091620 google .cloud .bigquery .job .QueryJob , instance = True
16101621 )
@@ -1689,6 +1700,7 @@ def test_bigquery_magic_with_option_value_incorrect(monkeypatch):
16891700 magics .context .credentials = mock .create_autospec (
16901701 google .auth .credentials .Credentials , instance = True
16911702 )
1703+ magics .context .project = "unit-test-project"
16921704
16931705 sql = "SELECT @foo AS foo"
16941706
@@ -1719,6 +1731,8 @@ def test_bigquery_magic_with_dict_params_negative_value(
17191731 run_query_patch = mock .patch (
17201732 "google.cloud.bigquery.magics.magics._run_query" , autospec = True
17211733 )
1734+ magics .context .project = "unit-test-project"
1735+
17221736 query_job_mock = mock .create_autospec (
17231737 google .cloud .bigquery .job .QueryJob , instance = True
17241738 )
@@ -1760,6 +1774,8 @@ def test_bigquery_magic_with_dict_params_array_value(ipython_ns_cleanup, monkeyp
17601774 run_query_patch = mock .patch (
17611775 "google.cloud.bigquery.magics.magics._run_query" , autospec = True
17621776 )
1777+ magics .context .project = "unit-test-project"
1778+
17631779 query_job_mock = mock .create_autospec (
17641780 google .cloud .bigquery .job .QueryJob , instance = True
17651781 )
@@ -1801,6 +1817,8 @@ def test_bigquery_magic_with_dict_params_tuple_value(ipython_ns_cleanup, monkeyp
18011817 run_query_patch = mock .patch (
18021818 "google.cloud.bigquery.magics.magics._run_query" , autospec = True
18031819 )
1820+ magics .context .project = "unit-test-project"
1821+
18041822 query_job_mock = mock .create_autospec (
18051823 google .cloud .bigquery .job .QueryJob , instance = True
18061824 )
@@ -1852,6 +1870,7 @@ def test_bigquery_magic_valid_query_in_existing_variable(
18521870 magics .context .credentials = mock .create_autospec (
18531871 google .auth .credentials .Credentials , instance = True
18541872 )
1873+ magics .context .project = "unit-test-project"
18551874
18561875 ipython_ns_cleanup .append ((ip , "custom_query" ))
18571876 ipython_ns_cleanup .append ((ip , "query_results_df" ))
@@ -1892,6 +1911,7 @@ def test_bigquery_magic_nonexisting_query_variable(monkeypatch):
18921911 magics .context .credentials = mock .create_autospec (
18931912 google .auth .credentials .Credentials , instance = True
18941913 )
1914+ magics .context .project = "unit-test-project"
18951915
18961916 run_query_patch = mock .patch (
18971917 "google.cloud.bigquery.magics.magics._run_query" , autospec = True
@@ -1917,7 +1937,7 @@ def test_bigquery_magic_empty_query_variable_name(monkeypatch):
19171937 magics .context .credentials = mock .create_autospec (
19181938 google .auth .credentials .Credentials , instance = True
19191939 )
1920-
1940+ magics . context . project = "unit-test-project"
19211941 run_query_patch = mock .patch (
19221942 "google.cloud.bigquery.magics.magics._run_query" , autospec = True
19231943 )
@@ -1940,6 +1960,7 @@ def test_bigquery_magic_query_variable_non_string(ipython_ns_cleanup, monkeypatc
19401960 magics .context .credentials = mock .create_autospec (
19411961 google .auth .credentials .Credentials , instance = True
19421962 )
1963+ magics .context .project = "unit-test-project"
19431964
19441965 run_query_patch = mock .patch (
19451966 "google.cloud.bigquery.magics.magics._run_query" , autospec = True
@@ -1968,9 +1989,14 @@ def test_bigquery_magic_query_variable_not_identifier(monkeypatch):
19681989 google .auth .credentials .Credentials , instance = True
19691990 )
19701991
1992+ magics .context .project = "unit-test-project"
19711993 cell_body = "$123foo" # 123foo is not valid Python identifier
19721994
1973- with io .capture_output () as captured_io :
1995+ run_query_patch = mock .patch (
1996+ "google.cloud.bigquery.magics.magics._run_query" , autospec = True
1997+ )
1998+
1999+ with run_query_patch , io .capture_output () as captured_io :
19742000 ip .run_cell_magic ("bigquery" , "" , cell_body )
19752001
19762002 # If "$" prefixes a string that is not a Python identifier, we do not treat such
0 commit comments