Skip to content

Commit 27ff3a8

Browse files
authored
fix: adds magics.context.project to eliminate issues with unit tests … (#2228)
Adds `magics.context.project` to eliminate issues with unit tests in an upcoming PR. Several magics unit tests fail with an error message. If the test does not have knowledge of the project, it attempts to initiate a login sequence to be able to get the project identifier. The login cannot complete because the process is running in an ipython interpreter and pytest does not capture any input. This change provides an explicit reference to a project to avoid that process. ``` Please visit this URL to authorize this application: [REDACTED DUE TO SPACE REASONS] self = <_pytest.capture.DontReadFromInput object at 0x7f55d6821bd0>, size = -1 def read(self, size: int = -1) -> str: > raise OSError( "pytest: reading from stdin while output is captured! Consider using `-s`.") E OSError: pytest: reading from stdin while output is captured! Consider using `-s`. .nox/unit-3-11/lib/python3.11/site-packages/_pytest/capture.py:229: OSError ```
1 parent 37e4e0e commit 27ff3a8

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

‎tests/unit/test_magics.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,7 @@ def test_bigquery_magic_dryrun_option_sets_job_config(monkeypatch):
986986
google.auth.credentials.Credentials, instance=True
987987
)
988988

989+
magics.context.project = "project-from-context"
989990
run_query_patch = mock.patch(
990991
"google.cloud.bigquery.magics.magics._run_query", autospec=True
991992
)
@@ -1007,6 +1008,7 @@ def test_bigquery_magic_dryrun_option_returns_query_job(monkeypatch):
10071008
magics.context.credentials = mock.create_autospec(
10081009
google.auth.credentials.Credentials, instance=True
10091010
)
1011+
magics.context.project = "project-from-context"
10101012
query_job_mock = mock.create_autospec(
10111013
google.cloud.bigquery.job.QueryJob, instance=True
10121014
)
@@ -1035,6 +1037,7 @@ def test_bigquery_magic_dryrun_option_variable_error_message(
10351037
google.auth.credentials.Credentials, instance=True
10361038
)
10371039

1040+
magics.context.project = "project-from-context"
10381041
ipython_ns_cleanup.append((ip, "q_job"))
10391042

10401043
run_query_patch = mock.patch(
@@ -1064,6 +1067,7 @@ def test_bigquery_magic_dryrun_option_saves_query_job_to_variable(
10641067
magics.context.credentials = mock.create_autospec(
10651068
google.auth.credentials.Credentials, instance=True
10661069
)
1070+
magics.context.project = "project-from-context"
10671071
query_job_mock = mock.create_autospec(
10681072
google.cloud.bigquery.job.QueryJob, instance=True
10691073
)
@@ -1098,6 +1102,7 @@ def test_bigquery_magic_saves_query_job_to_variable_on_error(
10981102
google.auth.credentials.Credentials, instance=True
10991103
)
11001104

1105+
magics.context.project = "project-from-context"
11011106
ipython_ns_cleanup.append((ip, "result"))
11021107

11031108
client_query_patch = mock.patch(

0 commit comments

Comments
 (0)