Skip to content

Commit 19ba3d0

Browse files
authored
Merge pull request #3124 from opentensor/fix/roman/py3.14-tests-issue
[v10] Fix py3.14 tests issue
2 parents 0f7e122 + 7f579e4 commit 19ba3d0

File tree

8 files changed

+52
-32
lines changed

8 files changed

+52
-32
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ check: ruff
3434
@mypy --ignore-missing-imports bittensor/ --python-version=3.11
3535
@mypy --ignore-missing-imports bittensor/ --python-version=3.12
3636
@mypy --ignore-missing-imports bittensor/ --python-version=3.13
37+
@mypy --ignore-missing-imports bittensor/ --python-version=3.14
3738
@flake8 bittensor/ --count

tests/e2e_tests/test_axon.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
import time
23

34
import pytest
45

@@ -10,8 +11,7 @@
1011
)
1112

1213

13-
@pytest.mark.asyncio
14-
async def test_axon(subtensor, templates, alice_wallet):
14+
def test_axon(subtensor, templates, alice_wallet):
1515
"""
1616
Test the Axon mechanism and successful registration on the network with sync Subtensor.
1717
@@ -45,9 +45,9 @@ async def test_axon(subtensor, templates, alice_wallet):
4545
assert old_axon.port == 0, f"Expected port 0, but got {old_axon.port}"
4646
assert old_axon.ip_type == 0, f"Expected IP type 0, but got {old_axon.ip_type}"
4747

48-
async with templates.miner(alice_wallet, alice_sn.netuid):
48+
with templates.miner(alice_wallet, alice_sn.netuid):
4949
# Waiting for 5 seconds for metagraph to be updated
50-
await asyncio.sleep(5)
50+
time.sleep(5)
5151

5252
# Refresh the metagraph
5353
metagraph = subtensor.metagraphs.metagraph(alice_sn.netuid)

tests/e2e_tests/test_dendrite.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
import time
23

34
import pytest
45

@@ -21,8 +22,7 @@
2122
NON_FAST_RUNTIME_TEMPO = 10
2223

2324

24-
@pytest.mark.asyncio
25-
async def test_dendrite(subtensor, templates, alice_wallet, bob_wallet):
25+
def test_dendrite(subtensor, templates, alice_wallet, bob_wallet):
2626
"""
2727
Test the Dendrite mechanism
2828
@@ -114,8 +114,8 @@ async def test_dendrite(subtensor, templates, alice_wallet, bob_wallet):
114114
assert bob_neuron.validator_trust == 0.0
115115
assert bob_neuron.pruning_score == 0
116116

117-
async with templates.validator(bob_wallet, alice_sn.netuid):
118-
await asyncio.sleep(5) # wait for 5 seconds for the Validator to process
117+
with templates.validator(bob_wallet, alice_sn.netuid):
118+
time.sleep(5) # wait for 5 seconds for the Validator to process
119119

120120
subtensor.wait_for_block(
121121
subtensor.subnets.get_next_epoch_start_block(alice_sn.netuid) + 1

tests/e2e_tests/test_incentive.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import asyncio
2-
2+
import time
33
import pytest
44

55
from bittensor.utils.btlogging import logging
@@ -16,8 +16,7 @@
1616
)
1717

1818

19-
@pytest.mark.asyncio
20-
async def test_incentive(subtensor, templates, alice_wallet, bob_wallet):
19+
def test_incentive(subtensor, templates, alice_wallet, bob_wallet):
2120
"""
2221
Test the incentive mechanism and interaction of miners/validators
2322
@@ -78,14 +77,11 @@ async def test_incentive(subtensor, templates, alice_wallet, bob_wallet):
7877
max_attempt = 3
7978
while True:
8079
try:
81-
async with templates.miner(bob_wallet, alice_sn.netuid) as miner:
82-
await asyncio.wait_for(miner.started.wait(), 60)
80+
with templates.miner(bob_wallet, alice_sn.netuid):
81+
time.sleep(5)
82+
with templates.validator(alice_wallet, alice_sn.netuid):
83+
time.sleep(5)
8384

84-
async with templates.validator(
85-
alice_wallet, alice_sn.netuid
86-
) as validator:
87-
# wait for the Validator to process and set_weights
88-
await asyncio.wait_for(validator.set_weights.wait(), 60)
8985
break
9086
except asyncio.TimeoutError:
9187
if max_attempt > 0:

tests/e2e_tests/test_neuron_certificate.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
)
88

99

10-
@pytest.mark.asyncio
11-
async def test_neuron_certificate(subtensor, alice_wallet):
10+
def test_neuron_certificate(subtensor, alice_wallet):
1211
"""
1312
Tests the metagraph
1413

tests/e2e_tests/test_root_set_weights.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import asyncio
2-
2+
import time
33
import pytest
44

55
from bittensor.extras.dev_framework import REGISTER_NEURON
@@ -36,8 +36,7 @@
3636
"""
3737

3838

39-
@pytest.mark.asyncio
40-
async def test_root_reg_hyperparams(subtensor, templates, alice_wallet, bob_wallet):
39+
def test_root_reg_hyperparams(subtensor, templates, alice_wallet, bob_wallet):
4140
"""
4241
Test root weights and hyperparameters in the Subtensor network.
4342
@@ -93,8 +92,8 @@ async def test_root_reg_hyperparams(subtensor, templates, alice_wallet, bob_wall
9392
period=16,
9493
).success, "Unable to stake from Bob to Alice"
9594

96-
async with templates.validator(alice_wallet, alice_sn.netuid):
97-
await asyncio.sleep(5) # Wait a bit for chain to process data
95+
with templates.validator(alice_wallet, alice_sn.netuid):
96+
time.sleep(5) # Wait a bit for chain to process data
9897

9998
# Fetch uid against Alice's hotkey on sn 2 (it will be 0 as she is the only registered neuron)
10099
alice_uid_sn_2 = subtensor.subnets.get_uid_for_hotkey_on_subnet(

tests/e2e_tests/test_subtensor_functions.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import asyncio
22
import re
3+
import time
4+
35
import pytest
46

57
from bittensor.utils.balance import Balance
@@ -32,8 +34,7 @@
3234
"""
3335

3436

35-
@pytest.mark.asyncio
36-
async def test_subtensor_extrinsics(subtensor, templates, alice_wallet, bob_wallet):
37+
def test_subtensor_extrinsics(subtensor, templates, alice_wallet, bob_wallet):
3738
"""
3839
Tests subtensor extrinsics
3940
@@ -165,10 +166,9 @@ async def test_subtensor_extrinsics(subtensor, templates, alice_wallet, bob_wall
165166
"Balance for Bob is not correct after burned register"
166167
)
167168

168-
async with templates.validator(alice_wallet, netuid):
169-
await asyncio.sleep(
170-
5
171-
) # wait for 5 seconds for the metagraph and subtensor to refresh with latest data
169+
with templates.validator(alice_wallet, netuid):
170+
# wait for 5 seconds for the metagraph and subtensor to refresh with latest data
171+
time.sleep(5)
172172

173173
alice_sn.wait_next_epoch()
174174

tests/e2e_tests/utils/e2e_test_utils.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,33 @@ def uninstall_templates(install_dir):
102102
shutil.rmtree(install_dir)
103103

104104

105+
def get_event_loop():
106+
"""Returns the current event loop or creates a new one if there is none."""
107+
try:
108+
loop = asyncio.get_running_loop()
109+
except RuntimeError:
110+
loop = asyncio.new_event_loop()
111+
asyncio.set_event_loop(loop)
112+
return loop
113+
114+
105115
class Templates:
106116
class Miner:
107117
def __init__(self, dir, wallet, netuid):
108118
self.dir = dir
109119
self.wallet = wallet
110120
self.netuid = netuid
111121
self.process = None
112-
122+
self.loop = get_event_loop()
113123
self.started = asyncio.Event()
114124

125+
def __enter__(self):
126+
self.loop.run_until_complete(self.__aenter__())
127+
return self
128+
129+
def __exit__(self, exc_type, exc_value, traceback):
130+
self.loop.run_until_complete(self.__aexit__(exc_type, exc_value, traceback))
131+
115132
async def __aenter__(self):
116133
env = os.environ.copy()
117134
env["BT_LOGGING_DEBUG"] = "1"
@@ -172,6 +189,7 @@ def __init__(self, dir, wallet, netuid):
172189
self.netuid = netuid
173190
self.process = None
174191

192+
self.loop = get_event_loop()
175193
self.started = asyncio.Event()
176194
self.set_weights = asyncio.Event()
177195

@@ -209,12 +227,19 @@ async def __aenter__(self):
209227

210228
return self
211229

230+
def __enter__(self):
231+
self.loop.run_until_complete(self.__aenter__())
232+
return self
233+
212234
async def __aexit__(self, exc_type, exc_value, traceback):
213235
self.process.terminate()
214236
self.__reader_task.cancel()
215237

216238
await self.process.wait()
217239

240+
def __exit__(self, exc_type, exc_value, traceback):
241+
self.loop.run_until_complete(self.__aexit__(exc_type, exc_value, traceback))
242+
218243
async def _reader(self):
219244
async for line in self.process.stdout:
220245
try:

0 commit comments

Comments
 (0)