Skip to content

Commit 1afa3bf

Browse files
jbmscopybara-github
authored andcommitted
Use --asyncio-mode=auto for pytest-asyncio to avoid explicit pytest.mark.asyncio
PiperOrigin-RevId: 823075751 Change-Id: Iaa1b63af0fec7db364f47a93e409a29d7ba83552
1 parent 0b5c455 commit 1afa3bf

File tree

7 files changed

+108
-98
lines changed

7 files changed

+108
-98
lines changed

bazel/pytest.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def tensorstore_pytest_test(
9393
pytest_args = [
9494
"-vv",
9595
"-s",
96+
"--asyncio-mode=auto",
9697
] + pytest_args,
9798
use_absl = use_absl,
9899
out = wrapper_script,

python/tensorstore/tests/downsample_test.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,17 @@
1414
"""Tests for tensorstore.downsample."""
1515

1616
import numpy as np
17-
import pytest
1817
import tensorstore as ts
1918

20-
pytestmark = pytest.mark.asyncio
21-
2219

2320
async def test_downsample_store_float32():
2421
t = ts.array(np.array([[1, 2, 3], [4, 5, 6]], dtype=np.float32))
2522

2623
downsampled = ts.downsample(t, [1, 2], method='mean')
2724

2825
np.testing.assert_equal(
29-
np.array([[1.5, 3], [4.5, 6]], dtype=np.float32), await
30-
downsampled.read())
26+
np.array([[1.5, 3], [4.5, 6]], dtype=np.float32), await downsampled.read()
27+
)
3128

3229

3330
async def test_downsample_store_uint32():
@@ -36,8 +33,8 @@ async def test_downsample_store_uint32():
3633
downsampled = ts.downsample(t, [2, 2], method='mean')
3734

3835
np.testing.assert_equal(
39-
np.array([[3, 4]], dtype=np.uint32), await
40-
downsampled.read())
36+
np.array([[3, 4]], dtype=np.uint32), await downsampled.read()
37+
)
4138

4239

4340
async def test_downsample_spec():
@@ -49,5 +46,5 @@ async def test_downsample_spec():
4946
downsampled = await ts.open(downsampled_spec)
5047

5148
np.testing.assert_equal(
52-
np.array([[1.5, 3], [4.5, 6]], dtype=np.float32), await
53-
downsampled.read())
49+
np.array([[1.5, 3], [4.5, 6]], dtype=np.float32), await downsampled.read()
50+
)

python/tensorstore/tests/experimental_test.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313
# limitations under the License.
1414
"""Tests for tensorstore.experimental methods."""
1515

16-
import pytest
1716
import tensorstore as ts
1817

1918

20-
@pytest.mark.asyncio
2119
async def test_collect_matching_metrics():
2220
# Open a tensorstore and read to ensure that some metric is populated.
2321
t = await ts.open({
@@ -33,7 +31,6 @@ async def test_collect_matching_metrics():
3331
assert m['name'].startswith('/tensorstore/')
3432

3533

36-
@pytest.mark.asyncio
3734
async def test_collect_prometheus_format_metrics():
3835
# Open a tensorstore and read to ensure that some metric is populated.
3936
t = await ts.open({

python/tensorstore/tests/future_test.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
import pytest
2323
import tensorstore as ts
2424

25-
pytestmark = pytest.mark.asyncio
26-
2725

2826
def test_promise_new():
2927
promise, future = ts.Promise.new()

python/tensorstore/tests/tensorstore_test.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
import pytest
2323
import tensorstore as ts
2424

25-
pytestmark = pytest.mark.asyncio
26-
2725

2826
async def test_open_array_driver():
2927
t = await ts.open({

python/tensorstore/tests/transaction_test.py

Lines changed: 101 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
import pytest
2121
import tensorstore as ts
2222

23-
pytestmark = pytest.mark.asyncio
24-
2523

2624
@contextlib.contextmanager
2725
def make_dataset():
@@ -33,9 +31,7 @@ def make_dataset():
3331
'path': dir_path,
3432
},
3533
'metadata': {
36-
'compression': {
37-
'type': 'gzip'
38-
},
34+
'compression': {'type': 'gzip'},
3935
'dataType': 'uint16',
4036
'dimensions': [3, 4],
4137
'blockSize': [2, 3],
@@ -53,112 +49,138 @@ async def test_transaction_read_write():
5349
assert txn.open
5450
dataset.with_transaction(txn)[1:2, 3:4] = 42
5551
dataset.with_transaction(txn)[0:2, :1] = 5
56-
np.testing.assert_equal([
57-
[5, 0, 0, 0],
58-
[5, 0, 0, 42],
59-
[0, 0, 0, 0],
60-
],
61-
dataset.with_transaction(txn).read().result())
62-
np.testing.assert_equal([
63-
[0, 0, 0, 0],
64-
[0, 0, 0, 0],
65-
[0, 0, 0, 0],
66-
],
67-
dataset.read().result())
52+
np.testing.assert_equal(
53+
[
54+
[5, 0, 0, 0],
55+
[5, 0, 0, 42],
56+
[0, 0, 0, 0],
57+
],
58+
dataset.with_transaction(txn).read().result(),
59+
)
60+
np.testing.assert_equal(
61+
[
62+
[0, 0, 0, 0],
63+
[0, 0, 0, 0],
64+
[0, 0, 0, 0],
65+
],
66+
dataset.read().result(),
67+
)
6868
txn.commit_async().result()
6969
assert txn.commit_started
7070
assert not txn.open
71-
np.testing.assert_equal([
72-
[5, 0, 0, 0],
73-
[5, 0, 0, 42],
74-
[0, 0, 0, 0],
75-
],
76-
dataset.read().result())
71+
np.testing.assert_equal(
72+
[
73+
[5, 0, 0, 0],
74+
[5, 0, 0, 42],
75+
[0, 0, 0, 0],
76+
],
77+
dataset.read().result(),
78+
)
7779

7880

7981
async def test_transaction_context_manager_commit():
8082
with make_dataset() as dataset:
8183
with ts.Transaction() as txn:
8284
dataset.with_transaction(txn)[1:2, 3:4] = 42
83-
np.testing.assert_equal([
84-
[0, 0, 0, 0],
85-
[0, 0, 0, 42],
86-
[0, 0, 0, 0],
87-
],
88-
dataset.with_transaction(txn).read().result())
89-
np.testing.assert_equal([
90-
[0, 0, 0, 0],
91-
[0, 0, 0, 0],
92-
[0, 0, 0, 0],
93-
],
94-
dataset.read().result())
95-
np.testing.assert_equal([
96-
[0, 0, 0, 0],
97-
[0, 0, 0, 42],
98-
[0, 0, 0, 0],
99-
],
100-
dataset.read().result())
85+
np.testing.assert_equal(
86+
[
87+
[0, 0, 0, 0],
88+
[0, 0, 0, 42],
89+
[0, 0, 0, 0],
90+
],
91+
dataset.with_transaction(txn).read().result(),
92+
)
93+
np.testing.assert_equal(
94+
[
95+
[0, 0, 0, 0],
96+
[0, 0, 0, 0],
97+
[0, 0, 0, 0],
98+
],
99+
dataset.read().result(),
100+
)
101+
np.testing.assert_equal(
102+
[
103+
[0, 0, 0, 0],
104+
[0, 0, 0, 42],
105+
[0, 0, 0, 0],
106+
],
107+
dataset.read().result(),
108+
)
101109

102110

103111
async def test_transaction_context_manager_abort():
104112
with make_dataset() as dataset:
105113
with pytest.raises(ValueError, match='want to abort'):
106114
with ts.Transaction() as txn:
107115
dataset.with_transaction(txn)[1:2, 3:4] = 42
108-
np.testing.assert_equal([
116+
np.testing.assert_equal(
117+
[
118+
[0, 0, 0, 0],
119+
[0, 0, 0, 42],
120+
[0, 0, 0, 0],
121+
],
122+
dataset.with_transaction(txn).read().result(),
123+
)
124+
raise ValueError('want to abort')
125+
np.testing.assert_equal(
126+
[
127+
[0, 0, 0, 0],
109128
[0, 0, 0, 0],
110-
[0, 0, 0, 42],
111129
[0, 0, 0, 0],
112130
],
113-
dataset.with_transaction(txn).read().result())
114-
raise ValueError('want to abort')
115-
np.testing.assert_equal([
116-
[0, 0, 0, 0],
117-
[0, 0, 0, 0],
118-
[0, 0, 0, 0],
119-
],
120-
dataset.read().result())
131+
dataset.read().result(),
132+
)
121133

122134

123135
async def test_transaction_async_context_manager_commit():
124136
with make_dataset() as dataset:
125137
async with ts.Transaction() as txn:
126138
dataset.with_transaction(txn)[1:2, 3:4] = 42
127-
np.testing.assert_equal([
128-
[0, 0, 0, 0],
129-
[0, 0, 0, 42],
130-
[0, 0, 0, 0],
131-
],
132-
dataset.with_transaction(txn).read().result())
133-
np.testing.assert_equal([
134-
[0, 0, 0, 0],
135-
[0, 0, 0, 0],
136-
[0, 0, 0, 0],
137-
],
138-
dataset.read().result())
139-
np.testing.assert_equal([
140-
[0, 0, 0, 0],
141-
[0, 0, 0, 42],
142-
[0, 0, 0, 0],
143-
],
144-
dataset.read().result())
139+
np.testing.assert_equal(
140+
[
141+
[0, 0, 0, 0],
142+
[0, 0, 0, 42],
143+
[0, 0, 0, 0],
144+
],
145+
dataset.with_transaction(txn).read().result(),
146+
)
147+
np.testing.assert_equal(
148+
[
149+
[0, 0, 0, 0],
150+
[0, 0, 0, 0],
151+
[0, 0, 0, 0],
152+
],
153+
dataset.read().result(),
154+
)
155+
np.testing.assert_equal(
156+
[
157+
[0, 0, 0, 0],
158+
[0, 0, 0, 42],
159+
[0, 0, 0, 0],
160+
],
161+
dataset.read().result(),
162+
)
145163

146164

147165
async def test_transaction_async_context_manager_abort():
148166
with make_dataset() as dataset:
149167
with pytest.raises(ValueError, match='want to abort'):
150168
async with ts.Transaction() as txn:
151169
dataset.with_transaction(txn)[1:2, 3:4] = 42
152-
np.testing.assert_equal([
170+
np.testing.assert_equal(
171+
[
172+
[0, 0, 0, 0],
173+
[0, 0, 0, 42],
174+
[0, 0, 0, 0],
175+
],
176+
dataset.with_transaction(txn).read().result(),
177+
)
178+
raise ValueError('want to abort')
179+
np.testing.assert_equal(
180+
[
181+
[0, 0, 0, 0],
153182
[0, 0, 0, 0],
154-
[0, 0, 0, 42],
155183
[0, 0, 0, 0],
156184
],
157-
dataset.with_transaction(txn).read().result())
158-
raise ValueError('want to abort')
159-
np.testing.assert_equal([
160-
[0, 0, 0, 0],
161-
[0, 0, 0, 0],
162-
[0, 0, 0, 0],
163-
],
164-
dataset.read().result())
185+
dataset.read().result(),
186+
)

python/tensorstore/tests/virtual_chunked_test.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,8 @@
1818

1919
import cloudpickle
2020
import numpy as np
21-
import pytest
2221
import tensorstore as ts
2322

24-
pytestmark = pytest.mark.asyncio
25-
2623

2724
def test_read_pickle():
2825
"""Tests reading, and that reading works after pickling."""

0 commit comments

Comments
 (0)