Skip to content

Commit 2140a51

Browse files
chore: Fix two types of warnings in unit tests (#2183)
* Fix two types of warnings in unit tests This commit addresses two warnings that appear when running unit tests: 1. `PytestRemovedIn9Warning` in `tests/unit/test_opentelemetry_tracing.py`: Removed a `@pytest.mark.skipif` decorator from a fixture. The skip condition is already present on the test methods using the fixture. 2. `FutureWarning` in `tests/unit/test_client.py`: Updated calls to `client.query()` to include `job_retry=None` when `job_id` is also specified. This is to avoid ambiguity as BigQuery cannot retry a failed job with the exact same ID. * Update tests/unit/test_client.py * Update tests/unit/test_client.py * Update linting * adds more examples of functions where job_retry is needed --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent ebfd0a8 commit 2140a51

File tree

2 files changed

+39
-14
lines changed

2 files changed

+39
-14
lines changed

tests/unit/test_client.py

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4719,7 +4719,7 @@ def test_query_w_api_method_query_and_job_id_fails(self):
47194719
client._connection = make_connection({})
47204720

47214721
with self.assertRaises(TypeError) as exc:
4722-
client.query(query, job_id="abcd", api_method="QUERY")
4722+
client.query(query, job_id="abcd", api_method="QUERY", job_retry=None)
47234723
self.assertIn(
47244724
"`job_id` was provided, but the 'QUERY' `api_method` was requested",
47254725
exc.exception.args[0],
@@ -4774,7 +4774,11 @@ def test_query_w_explicit_project(self):
47744774
conn = client._connection = make_connection(resource)
47754775

47764776
client.query(
4777-
query, job_id=job_id, project="other-project", location=self.LOCATION
4777+
query,
4778+
job_id=job_id,
4779+
project="other-project",
4780+
location=self.LOCATION,
4781+
job_retry=None,
47784782
)
47794783

47804784
# Check that query actually starts the job.
@@ -4833,7 +4837,11 @@ def test_query_w_explicit_job_config(self):
48334837
original_config_copy = copy.deepcopy(job_config)
48344838

48354839
client.query(
4836-
query, job_id=job_id, location=self.LOCATION, job_config=job_config
4840+
query,
4841+
job_id=job_id,
4842+
location=self.LOCATION,
4843+
job_config=job_config,
4844+
job_retry=None,
48374845
)
48384846

48394847
# Check that query actually starts the job.
@@ -4884,7 +4892,11 @@ def test_query_preserving_explicit_job_config(self):
48844892
original_config_copy = copy.deepcopy(job_config)
48854893

48864894
client.query(
4887-
query, job_id=job_id, location=self.LOCATION, job_config=job_config
4895+
query,
4896+
job_id=job_id,
4897+
location=self.LOCATION,
4898+
job_config=job_config,
4899+
job_retry=None,
48884900
)
48894901

48904902
# Check that query actually starts the job.
@@ -4940,7 +4952,13 @@ def test_query_preserving_explicit_default_job_config(self):
49404952
)
49414953
conn = client._connection = make_connection(resource)
49424954

4943-
client.query(query, job_id=job_id, location=self.LOCATION, job_config=None)
4955+
client.query(
4956+
query,
4957+
job_id=job_id,
4958+
location=self.LOCATION,
4959+
job_config=None,
4960+
job_retry=None,
4961+
)
49444962

49454963
# Check that query actually starts the job.
49464964
conn.api_request.assert_called_once_with(
@@ -4978,7 +4996,11 @@ def test_query_w_invalid_job_config(self):
49784996

49794997
with self.assertRaises(TypeError) as exc:
49804998
client.query(
4981-
query, job_id=job_id, location=self.LOCATION, job_config=job_config
4999+
query,
5000+
job_id=job_id,
5001+
location=self.LOCATION,
5002+
job_config=job_config,
5003+
job_retry=None,
49825004
)
49835005
self.assertIn("Expected an instance of QueryJobConfig", exc.exception.args[0])
49845006

@@ -5027,7 +5049,11 @@ def test_query_w_explicit_job_config_override(self):
50275049
job_config.default_dataset = None
50285050

50295051
client.query(
5030-
query, job_id=job_id, location=self.LOCATION, job_config=job_config
5052+
query,
5053+
job_id=job_id,
5054+
location=self.LOCATION,
5055+
job_config=job_config,
5056+
job_retry=None,
50315057
)
50325058

50335059
# Check that query actually starts the job.
@@ -5072,7 +5098,7 @@ def test_query_w_client_default_config_no_incoming(self):
50725098
)
50735099
conn = client._connection = make_connection(resource)
50745100

5075-
client.query(query, job_id=job_id, location=self.LOCATION)
5101+
client.query(query, job_id=job_id, location=self.LOCATION, job_retry=None)
50765102

50775103
# Check that query actually starts the job.
50785104
conn.api_request.assert_called_once_with(
@@ -5114,7 +5140,7 @@ def test_query_w_client_location(self):
51145140
)
51155141
conn = client._connection = make_connection(resource)
51165142

5117-
client.query(query, job_id=job_id, project="other-project")
5143+
client.query(query, job_id=job_id, project="other-project", job_retry=None)
51185144

51195145
# Check that query actually starts the job.
51205146
conn.api_request.assert_called_once_with(
@@ -5178,7 +5204,7 @@ def test_query_w_udf_resources(self):
51785204
config.udf_resources = udf_resources
51795205
config.use_legacy_sql = True
51805206

5181-
job = client.query(QUERY, job_config=config, job_id=JOB)
5207+
job = client.query(QUERY, job_config=config, job_id=JOB, job_retry=None)
51825208

51835209
self.assertIsInstance(job, QueryJob)
51845210
self.assertIs(job._client, client)
@@ -5234,7 +5260,7 @@ def test_query_w_query_parameters(self):
52345260
config = QueryJobConfig()
52355261
config.query_parameters = query_parameters
52365262

5237-
job = client.query(QUERY, job_config=config, job_id=JOB)
5263+
job = client.query(QUERY, job_config=config, job_id=JOB, job_retry=None)
52385264

52395265
self.assertIsInstance(job, QueryJob)
52405266
self.assertIs(job._client, client)
@@ -5277,7 +5303,7 @@ def test_query_job_rpc_fail_w_random_error(self):
52775303
)
52785304
with job_begin_patcher:
52795305
with pytest.raises(Unknown, match="Not sure what went wrong."):
5280-
client.query("SELECT 1;", job_id="123")
5306+
client.query("SELECT 1;", job_id="123", job_retry=None)
52815307

52825308
def test_query_job_rpc_fail_w_conflict_job_id_given(self):
52835309
from google.api_core.exceptions import Conflict
@@ -5293,7 +5319,7 @@ def test_query_job_rpc_fail_w_conflict_job_id_given(self):
52935319
)
52945320
with job_begin_patcher:
52955321
with pytest.raises(Conflict, match="Job already exists."):
5296-
client.query("SELECT 1;", job_id="123")
5322+
client.query("SELECT 1;", job_id="123", job_retry=None)
52975323

52985324
def test_query_job_rpc_fail_w_conflict_random_id_job_fetch_fails(self):
52995325
from google.api_core.exceptions import Conflict

tests/unit/test_opentelemetry_tracing.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
TEST_SPAN_ATTRIBUTES = {"foo": "baz"}
4343

4444

45-
@pytest.mark.skipif(opentelemetry is None, reason="Require `opentelemetry`")
4645
@pytest.fixture
4746
def setup():
4847
importlib.reload(opentelemetry_tracing)

0 commit comments

Comments
 (0)