From e1192c2a7676ab294c83cf072241b11051e1012d Mon Sep 17 00:00:00 2001 From: Peter Lamut Date: Mon, 22 Jul 2019 12:37:57 +0200 Subject: [PATCH] Mock external calls in one of BigQuery unit tests --- bigquery/tests/unit/test_magics.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/bigquery/tests/unit/test_magics.py b/bigquery/tests/unit/test_magics.py index 6e8c941bbc028..7cb153230f4d8 100644 --- a/bigquery/tests/unit/test_magics.py +++ b/bigquery/tests/unit/test_magics.py @@ -559,9 +559,17 @@ def test_bigquery_magic_w_maximum_bytes_billed_invalid(): ip.extension_manager.load_extension("google.cloud.bigquery") magics.context._project = None + credentials_mock = mock.create_autospec( + google.auth.credentials.Credentials, instance=True + ) + default_patch = mock.patch( + "google.auth.default", return_value=(credentials_mock, "general-project") + ) + client_query_patch = mock.patch("google.cloud.bigquery.client.Client.query") + sql = "SELECT 17 AS num" - with pytest.raises(ValueError): + with pytest.raises(ValueError), default_patch, client_query_patch: ip.run_cell_magic("bigquery", "--maximum_bytes_billed=abc", sql)