Skip to content

Commit 58b2ac5

Browse files
authored
chore: make test_read_gbq_colab_includes_label more robust to python changes (#2342)
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/python-bigquery-dataframes/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) Fixes b/469510777 🦕
1 parent ea71936 commit 58b2ac5

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

tests/unit/session/test_read_gbq_colab.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
"""Unit tests for read_gbq_colab helper functions."""
1616

17+
import itertools
1718
import textwrap
1819
from unittest import mock
1920

@@ -27,15 +28,21 @@
2728

2829
def test_read_gbq_colab_includes_label():
2930
"""Make sure we can tell direct colab usage apart from regular read_gbq usage."""
30-
session = mocks.create_bigquery_session()
31+
bqclient = mock.create_autospec(bigquery.Client, instance=True)
32+
bqclient.project = "proj"
33+
session = mocks.create_bigquery_session(bqclient=bqclient)
3134
_ = session._read_gbq_colab("SELECT 'read-gbq-colab-test'")
32-
configs = session._job_configs # type: ignore
3335

3436
label_values = []
35-
for config in configs:
36-
if config is None:
37+
for kall in itertools.chain(
38+
bqclient.query_and_wait.call_args_list,
39+
bqclient._query_and_wait_bigframes.call_args_list,
40+
bqclient.query.call_args_list,
41+
):
42+
job_config = kall.kwargs.get("job_config")
43+
if job_config is None:
3744
continue
38-
label_values.extend(config.labels.values())
45+
label_values.extend(job_config.labels.values())
3946

4047
assert "session-read_gbq_colab" in label_values
4148

0 commit comments

Comments
 (0)