Skip to content

Commit 91bafe5

Browse files
committed
Change pytest scope to function for all integration tests:
- Instantiate a new geth instance for each test to avoid muddied context between tests - Lower the ``dev.period`` to ``1`` since the tests don't need to account for each other anymore - Parallelize the tests in CI with pytest-xdist (``-n 10``) - Properly disconnect the ``async_await_w3`` ws tests
1 parent 48ec2d0 commit 91bafe5

File tree

14 files changed

+101
-137
lines changed

14 files changed

+101
-137
lines changed

newsfragments/3659.internal.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Run each integration test in isolation and parallelize, instead of running them all within a single `geth` (for example) process. This prevents muddied test contexts.

tests/integration/conftest.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,47 +19,47 @@
1919
)
2020

2121

22-
@pytest.fixture(scope="module")
22+
@pytest.fixture
2323
def math_contract_factory(w3):
2424
contract_factory = w3.eth.contract(
2525
abi=MATH_CONTRACT_ABI, bytecode=MATH_CONTRACT_BYTECODE
2626
)
2727
return contract_factory
2828

2929

30-
@pytest.fixture(scope="module")
30+
@pytest.fixture
3131
def emitter_contract_factory(w3):
3232
contract_factory = w3.eth.contract(
3333
abi=EMITTER_CONTRACT_ABI, bytecode=EMITTER_CONTRACT_BYTECODE
3434
)
3535
return contract_factory
3636

3737

38-
@pytest.fixture(scope="module")
38+
@pytest.fixture
3939
def revert_contract_factory(w3):
4040
contract_factory = w3.eth.contract(
4141
abi=REVERT_CONTRACT_ABI, bytecode=REVERT_CONTRACT_BYTECODE
4242
)
4343
return contract_factory
4444

4545

46-
@pytest.fixture(scope="module")
46+
@pytest.fixture
4747
def offchain_lookup_contract_factory(w3):
4848
contract_factory = w3.eth.contract(
4949
abi=OFFCHAIN_LOOKUP_ABI, bytecode=OFFCHAIN_LOOKUP_BYTECODE
5050
)
5151
return contract_factory
5252

5353

54-
@pytest.fixture(scope="module")
54+
@pytest.fixture
5555
def async_offchain_lookup_contract_factory(async_w3):
5656
contract_factory = async_w3.eth.contract(
5757
abi=OFFCHAIN_LOOKUP_ABI, bytecode=OFFCHAIN_LOOKUP_BYTECODE
5858
)
5959
return contract_factory
6060

6161

62-
@pytest.fixture(scope="module")
62+
@pytest.fixture
6363
def event_loop():
6464
loop = asyncio.get_event_loop_policy().new_event_loop()
6565
yield loop

tests/integration/go_ethereum/conftest.py

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
GETH_FIXTURE_ZIP = "geth-1.15.5-fixture.zip"
3838

3939

40-
@pytest.fixture(scope="module")
40+
@pytest.fixture
4141
def geth_binary():
4242
from geth.install import (
4343
get_executable_path,
@@ -67,7 +67,7 @@ def absolute_datadir(directory_name):
6767
)
6868

6969

70-
@pytest.fixture(scope="module")
70+
@pytest.fixture
7171
def get_geth_version(geth_binary):
7272
from geth import (
7373
get_geth_version,
@@ -86,15 +86,15 @@ def get_geth_version(geth_binary):
8686
return geth_version
8787

8888

89-
@pytest.fixture(scope="module")
89+
@pytest.fixture
9090
def base_geth_command_arguments(geth_binary, datadir):
9191
return (
9292
geth_binary,
9393
"--datadir",
9494
datadir,
9595
"--dev",
9696
"--dev.period",
97-
"2",
97+
"1",
9898
"--password",
9999
os.path.join(datadir, "keystore", "pw.txt"),
100100
# in order to raise on underpriced transactions, ``txpool.nolocals`` is now
@@ -103,15 +103,15 @@ def base_geth_command_arguments(geth_binary, datadir):
103103
)
104104

105105

106-
@pytest.fixture(scope="module")
106+
@pytest.fixture
107107
def geth_zipfile_version(get_geth_version):
108108
# TODO: Remove support for 1.13.x in next major version
109109
if get_geth_version.major == 1 and get_geth_version.minor in [13, 14, 15]:
110110
return GETH_FIXTURE_ZIP
111111
raise AssertionError("Unsupported geth version")
112112

113113

114-
@pytest.fixture(scope="module")
114+
@pytest.fixture
115115
def datadir(tmpdir_factory, geth_zipfile_version):
116116
zipfile_path = absolute_datadir(geth_zipfile_version)
117117
base_dir = tmpdir_factory.mktemp("goethereum")
@@ -121,19 +121,19 @@ def datadir(tmpdir_factory, geth_zipfile_version):
121121
return tmp_datadir
122122

123123

124-
@pytest.fixture(scope="module")
124+
@pytest.fixture
125125
def geth_fixture_data(datadir):
126126
config_file_path = Path(datadir) / "config.json"
127127
return json.loads(config_file_path.read_text())
128128

129129

130-
@pytest.fixture(scope="module")
130+
@pytest.fixture
131131
def genesis_file(datadir):
132132
genesis_file_path = os.path.join(datadir, "genesis.json")
133133
return genesis_file_path
134134

135135

136-
@pytest.fixture(scope="module")
136+
@pytest.fixture
137137
def geth_process(geth_binary, datadir, genesis_file, geth_command_arguments):
138138
init_datadir_command = (
139139
geth_binary,
@@ -165,100 +165,100 @@ def geth_process(geth_binary, datadir, genesis_file, geth_command_arguments):
165165
)
166166

167167

168-
@pytest.fixture(scope="module")
168+
@pytest.fixture
169169
def math_contract_deploy_txn_hash(geth_fixture_data):
170170
return geth_fixture_data["math_deploy_txn_hash"]
171171

172172

173-
@pytest.fixture(scope="module")
173+
@pytest.fixture
174174
def math_contract(math_contract_factory, geth_fixture_data):
175175
return math_contract_factory(address=geth_fixture_data["math_address"])
176176

177177

178-
@pytest.fixture(scope="module")
178+
@pytest.fixture
179179
def math_contract_address(math_contract, address_conversion_func):
180180
return address_conversion_func(math_contract.address)
181181

182182

183-
@pytest.fixture(scope="module")
183+
@pytest.fixture
184184
def emitter_contract(emitter_contract_factory, geth_fixture_data):
185185
return emitter_contract_factory(address=geth_fixture_data["emitter_address"])
186186

187187

188-
@pytest.fixture(scope="module")
188+
@pytest.fixture
189189
def emitter_contract_address(emitter_contract, address_conversion_func):
190190
return address_conversion_func(emitter_contract.address)
191191

192192

193-
@pytest.fixture(scope="module")
193+
@pytest.fixture
194194
def keyfile_account_pkey(geth_fixture_data):
195195
return geth_fixture_data["keyfile_account_pkey"]
196196

197197

198-
@pytest.fixture(scope="module")
198+
@pytest.fixture
199199
def keyfile_account_address(geth_fixture_data):
200200
return geth_fixture_data["keyfile_account_address"]
201201

202202

203-
@pytest.fixture(scope="module")
203+
@pytest.fixture
204204
def keyfile_account_address_dual_type(keyfile_account_address, address_conversion_func):
205205
yield keyfile_account_address
206206

207207

208-
@pytest.fixture(scope="module")
208+
@pytest.fixture
209209
def empty_block(w3, geth_fixture_data):
210210
block = w3.eth.get_block(geth_fixture_data["empty_block_hash"])
211211
assert is_dict(block)
212212
return block
213213

214214

215-
@pytest.fixture(scope="module")
215+
@pytest.fixture
216216
def block_with_txn(w3, geth_fixture_data):
217217
block = w3.eth.get_block(geth_fixture_data["block_with_txn_hash"])
218218
assert is_dict(block)
219219
return block
220220

221221

222-
@pytest.fixture(scope="module")
222+
@pytest.fixture
223223
def mined_txn_hash(geth_fixture_data):
224224
return geth_fixture_data["mined_txn_hash"]
225225

226226

227-
@pytest.fixture(scope="module")
227+
@pytest.fixture
228228
def block_with_txn_with_log(w3, geth_fixture_data):
229229
block = w3.eth.get_block(geth_fixture_data["block_hash_with_log"])
230230
assert is_dict(block)
231231
return block
232232

233233

234-
@pytest.fixture(scope="module")
234+
@pytest.fixture
235235
def txn_hash_with_log(geth_fixture_data):
236236
return geth_fixture_data["txn_hash_with_log"]
237237

238238

239-
@pytest.fixture(scope="module")
239+
@pytest.fixture
240240
def block_hash_revert_no_msg(geth_fixture_data):
241241
return geth_fixture_data["block_hash_revert_no_msg"]
242242

243243

244-
@pytest.fixture(scope="module")
244+
@pytest.fixture
245245
def block_hash_revert_with_msg(geth_fixture_data):
246246
return geth_fixture_data["block_hash_revert_with_msg"]
247247

248248

249-
@pytest.fixture(scope="module")
249+
@pytest.fixture
250250
def revert_contract(revert_contract_factory, geth_fixture_data):
251251
return revert_contract_factory(address=geth_fixture_data["revert_address"])
252252

253253

254-
@pytest.fixture(scope="module")
254+
@pytest.fixture
255255
def offchain_lookup_contract(offchain_lookup_contract_factory, geth_fixture_data):
256256
return offchain_lookup_contract_factory(
257257
address=geth_fixture_data["offchain_lookup_address"]
258258
)
259259

260260

261-
@pytest.fixture(scope="module")
261+
@pytest.fixture
262262
def panic_errors_contract(
263263
w3,
264264
geth_fixture_data,
@@ -267,7 +267,7 @@ def panic_errors_contract(
267267
return contract_factory(address=geth_fixture_data["panic_errors_contract_address"])
268268

269269

270-
@pytest.fixture(scope="module")
270+
@pytest.fixture
271271
def storage_contract(
272272
w3,
273273
geth_fixture_data,
@@ -279,19 +279,19 @@ def storage_contract(
279279
# --- async --- #
280280

281281

282-
@pytest_asyncio.fixture(scope="module")
282+
@pytest_asyncio.fixture
283283
async def async_keyfile_account_address(geth_fixture_data):
284284
return geth_fixture_data["keyfile_account_address"]
285285

286286

287-
@pytest_asyncio.fixture(scope="module")
287+
@pytest_asyncio.fixture
288288
async def async_keyfile_account_address_dual_type(
289289
async_keyfile_account_address, address_conversion_func
290290
):
291291
yield async_keyfile_account_address
292292

293293

294-
@pytest.fixture(scope="module")
294+
@pytest.fixture
295295
def async_offchain_lookup_contract(
296296
async_offchain_lookup_contract_factory, geth_fixture_data
297297
):
@@ -300,7 +300,7 @@ def async_offchain_lookup_contract(
300300
)
301301

302302

303-
@pytest.fixture(scope="module")
303+
@pytest.fixture
304304
def async_panic_errors_contract(
305305
async_w3,
306306
geth_fixture_data,
@@ -309,35 +309,35 @@ def async_panic_errors_contract(
309309
return contract_factory(address=geth_fixture_data["panic_errors_contract_address"])
310310

311311

312-
@pytest.fixture(scope="module")
312+
@pytest.fixture
313313
def async_emitter_contract(async_w3, geth_fixture_data):
314314
contract_factory = async_w3.eth.contract(**EMITTER_CONTRACT_DATA)
315315
return contract_factory(address=geth_fixture_data["emitter_address"])
316316

317317

318-
@pytest.fixture(scope="module")
318+
@pytest.fixture
319319
def async_emitter_contract_address(async_emitter_contract, address_conversion_func):
320320
return address_conversion_func(async_emitter_contract.address)
321321

322322

323-
@pytest.fixture(scope="module")
323+
@pytest.fixture
324324
def async_math_contract(async_w3, geth_fixture_data):
325325
contract_factory = async_w3.eth.contract(**MATH_CONTRACT_DATA)
326326
return contract_factory(address=geth_fixture_data["math_address"])
327327

328328

329-
@pytest.fixture(scope="module")
329+
@pytest.fixture
330330
def async_math_contract_address(async_math_contract, address_conversion_func):
331331
return address_conversion_func(async_math_contract.address)
332332

333333

334-
@pytest.fixture(scope="module")
334+
@pytest.fixture
335335
def async_revert_contract(async_w3, geth_fixture_data):
336336
contract_factory = async_w3.eth.contract(**REVERT_CONTRACT_DATA)
337337
return contract_factory(address=geth_fixture_data["revert_address"])
338338

339339

340-
@pytest.fixture(scope="module")
340+
@pytest.fixture
341341
def async_storage_contract(
342342
async_w3,
343343
geth_fixture_data,
@@ -346,21 +346,21 @@ def async_storage_contract(
346346
return contract_factory(address=geth_fixture_data["storage_contract_address"])
347347

348348

349-
@pytest_asyncio.fixture(scope="module")
349+
@pytest_asyncio.fixture
350350
async def async_empty_block(async_w3, geth_fixture_data):
351351
block = await async_w3.eth.get_block(geth_fixture_data["empty_block_hash"])
352352
assert is_dict(block)
353353
return block
354354

355355

356-
@pytest_asyncio.fixture(scope="module")
356+
@pytest_asyncio.fixture
357357
async def async_block_with_txn(async_w3, geth_fixture_data):
358358
block = await async_w3.eth.get_block(geth_fixture_data["block_with_txn_hash"])
359359
assert is_dict(block)
360360
return block
361361

362362

363-
@pytest_asyncio.fixture(scope="module")
363+
@pytest_asyncio.fixture
364364
async def async_block_with_txn_with_log(async_w3, geth_fixture_data):
365365
block = await async_w3.eth.get_block(geth_fixture_data["block_hash_with_log"])
366366
assert is_dict(block)

0 commit comments

Comments
 (0)