Skip to content

Commit 36b5fd1

Browse files
Don't repeat tests (#643)
* Don't repeat tests * Format code
1 parent f41934a commit 36b5fd1

File tree

2 files changed

+28
-41
lines changed

2 files changed

+28
-41
lines changed

tests/conftest.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,6 @@
44
import pytest
55

66

7-
def pytest_addoption(parser):
8-
parser.addoption(
9-
"--repeat", type=int, default=1, help="repeat the operation multiple times"
10-
)
11-
12-
13-
@pytest.fixture(scope="session")
14-
def repeat(request):
15-
return request.config.getoption("repeat")
16-
17-
187
@pytest.fixture
198
def reset_sys_path():
209
original = copy.deepcopy(sys.path)

tests/test_inputs.py

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -174,22 +174,21 @@ def test_message_equality(test_data: TestData) -> None:
174174

175175

176176
@pytest.mark.parametrize("test_data", test_cases.messages_with_json, indirect=True)
177-
def test_message_json(repeat, test_data: TestData) -> None:
177+
def test_message_json(test_data: TestData) -> None:
178178
plugin_module, _, json_data = test_data
179179

180-
for _ in range(repeat):
181-
for sample in json_data:
182-
if sample.belongs_to(test_input_config.non_symmetrical_json):
183-
continue
180+
for sample in json_data:
181+
if sample.belongs_to(test_input_config.non_symmetrical_json):
182+
continue
184183

185-
message: betterproto.Message = plugin_module.Test()
184+
message: betterproto.Message = plugin_module.Test()
186185

187-
message.from_json(sample.json)
188-
message_json = message.to_json(0)
186+
message.from_json(sample.json)
187+
message_json = message.to_json(0)
189188

190-
assert dict_replace_nans(json.loads(message_json)) == dict_replace_nans(
191-
json.loads(sample.json)
192-
)
189+
assert dict_replace_nans(json.loads(message_json)) == dict_replace_nans(
190+
json.loads(sample.json)
191+
)
193192

194193

195194
@pytest.mark.parametrize("test_data", test_cases.services, indirect=True)
@@ -198,28 +197,27 @@ def test_service_can_be_instantiated(test_data: TestData) -> None:
198197

199198

200199
@pytest.mark.parametrize("test_data", test_cases.messages_with_json, indirect=True)
201-
def test_binary_compatibility(repeat, test_data: TestData) -> None:
200+
def test_binary_compatibility(test_data: TestData) -> None:
202201
plugin_module, reference_module, json_data = test_data
203202

204203
for sample in json_data:
205204
reference_instance = Parse(sample.json, reference_module().Test())
206205
reference_binary_output = reference_instance.SerializeToString()
207206

208-
for _ in range(repeat):
209-
plugin_instance_from_json: betterproto.Message = (
210-
plugin_module.Test().from_json(sample.json)
211-
)
212-
plugin_instance_from_binary = plugin_module.Test.FromString(
213-
reference_binary_output
214-
)
215-
216-
# Generally this can't be relied on, but here we are aiming to match the
217-
# existing Python implementation and aren't doing anything tricky.
218-
# https://developers.google.com/protocol-buffers/docs/encoding#implications
219-
assert bytes(plugin_instance_from_json) == reference_binary_output
220-
assert bytes(plugin_instance_from_binary) == reference_binary_output
221-
222-
assert plugin_instance_from_json == plugin_instance_from_binary
223-
assert dict_replace_nans(
224-
plugin_instance_from_json.to_dict()
225-
) == dict_replace_nans(plugin_instance_from_binary.to_dict())
207+
plugin_instance_from_json: betterproto.Message = plugin_module.Test().from_json(
208+
sample.json
209+
)
210+
plugin_instance_from_binary = plugin_module.Test.FromString(
211+
reference_binary_output
212+
)
213+
214+
# Generally this can't be relied on, but here we are aiming to match the
215+
# existing Python implementation and aren't doing anything tricky.
216+
# https://developers.google.com/protocol-buffers/docs/encoding#implications
217+
assert bytes(plugin_instance_from_json) == reference_binary_output
218+
assert bytes(plugin_instance_from_binary) == reference_binary_output
219+
220+
assert plugin_instance_from_json == plugin_instance_from_binary
221+
assert dict_replace_nans(
222+
plugin_instance_from_json.to_dict()
223+
) == dict_replace_nans(plugin_instance_from_binary.to_dict())

0 commit comments

Comments
 (0)