Skip to content

Commit 0392627

Browse files
authored
Merge pull request #2660 from opentensor/tests/zyzniewski/e2e_templates_teardown
Tests: separate `templates` fixture
2 parents 9e4ce58 + 93b7b25 commit 0392627

File tree

7 files changed

+39
-49
lines changed

7 files changed

+39
-49
lines changed

tests/e2e_tests/conftest.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,6 @@ def local_chain(request):
4949

5050
# Pattern match indicates node is compiled and ready
5151
pattern = re.compile(r"Imported #1")
52-
53-
# install neuron templates
54-
logging.info("downloading and installing neuron templates from github")
55-
# commit with subnet-template-repo changes for rust wallet
56-
templates_dir = clone_or_update_templates()
57-
install_templates(templates_dir)
58-
5952
timestamp = int(time.time())
6053

6154
def wait_for_node_start(process, pattern):
@@ -87,7 +80,7 @@ def read_output():
8780
wait_for_node_start(process, pattern)
8881

8982
# Run the test, passing in substrate interface
90-
yield SubstrateInterface(url="ws://127.0.0.1:9945")
83+
yield SubstrateInterface(url="ws://127.0.0.1:9944")
9184

9285
# Terminate the process group (includes all child processes)
9386
os.killpg(os.getpgid(process.pid), signal.SIGTERM)
@@ -102,14 +95,25 @@ def read_output():
10295
# Ensure the process has terminated
10396
process.wait()
10497

105-
# uninstall templates
98+
99+
@pytest.fixture
100+
def templates():
101+
logging.info("downloading and installing neuron templates from github")
102+
103+
templates_dir = clone_or_update_templates()
104+
105+
install_templates(templates_dir)
106+
107+
yield templates_dir
108+
106109
logging.info("uninstalling neuron templates")
110+
107111
uninstall_templates(template_path)
108112

109113

110114
@pytest.fixture
111115
def subtensor(local_chain):
112-
return Subtensor(network="ws://localhost:9945")
116+
return Subtensor(network="ws://localhost:9944")
113117

114118

115119
@pytest.fixture

tests/e2e_tests/test_axon.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,10 @@
44
import pytest
55

66
from bittensor.utils import networking
7-
from tests.e2e_tests.utils.e2e_test_utils import (
8-
template_path,
9-
templates_repo,
10-
)
117

128

139
@pytest.mark.asyncio
14-
async def test_axon(subtensor, alice_wallet):
10+
async def test_axon(subtensor, templates, alice_wallet):
1511
"""
1612
Test the Axon mechanism and successful registration on the network.
1713
@@ -53,13 +49,13 @@ async def test_axon(subtensor, alice_wallet):
5349
cmd = " ".join(
5450
[
5551
f"{sys.executable}",
56-
f'"{template_path}{templates_repo}/miner.py"',
52+
f'"{templates}/miner.py"',
5753
"--netuid",
5854
str(netuid),
5955
"--subtensor.network",
6056
"local",
6157
"--subtensor.chain_endpoint",
62-
"ws://localhost:9945",
58+
"ws://localhost:9944",
6359
"--wallet.path",
6460
alice_wallet.path,
6561
"--wallet.name",

tests/e2e_tests/test_dendrite.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,10 @@
1010
sudo_set_hyperparameter_values,
1111
wait_epoch,
1212
)
13-
from tests.e2e_tests.utils.e2e_test_utils import (
14-
template_path,
15-
templates_repo,
16-
)
1713

1814

1915
@pytest.mark.asyncio
20-
async def test_dendrite(local_chain, subtensor, alice_wallet, bob_wallet):
16+
async def test_dendrite(local_chain, subtensor, templates, alice_wallet, bob_wallet):
2117
"""
2218
Test the Dendrite mechanism
2319
@@ -112,13 +108,13 @@ async def test_dendrite(local_chain, subtensor, alice_wallet, bob_wallet):
112108
cmd = " ".join(
113109
[
114110
f"{sys.executable}",
115-
f'"{template_path}{templates_repo}/validator.py"',
111+
f'"{templates}/validator.py"',
116112
"--netuid",
117113
str(netuid),
118114
"--subtensor.network",
119115
"local",
120116
"--subtensor.chain_endpoint",
121-
"ws://localhost:9945",
117+
"ws://localhost:9944",
122118
"--wallet.path",
123119
bob_wallet.path,
124120
"--wallet.name",

tests/e2e_tests/test_incentive.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,10 @@
77
sudo_set_hyperparameter_values,
88
wait_epoch,
99
)
10-
from tests.e2e_tests.utils.e2e_test_utils import (
11-
template_path,
12-
templates_repo,
13-
)
1410

1511

1612
@pytest.mark.asyncio
17-
async def test_incentive(local_chain, subtensor, alice_wallet, bob_wallet):
13+
async def test_incentive(local_chain, subtensor, templates, alice_wallet, bob_wallet):
1814
"""
1915
Test the incentive mechanism and interaction of miners/validators
2016
@@ -75,13 +71,13 @@ async def test_incentive(local_chain, subtensor, alice_wallet, bob_wallet):
7571
cmd = " ".join(
7672
[
7773
f"{sys.executable}",
78-
f'"{template_path}{templates_repo}/miner.py"',
74+
f'"{templates}/miner.py"',
7975
"--netuid",
8076
str(netuid),
8177
"--subtensor.network",
8278
"local",
8379
"--subtensor.chain_endpoint",
84-
"ws://localhost:9945",
80+
"ws://localhost:9944",
8581
"--wallet.path",
8682
bob_wallet.path,
8783
"--wallet.name",
@@ -104,13 +100,13 @@ async def test_incentive(local_chain, subtensor, alice_wallet, bob_wallet):
104100
cmd = " ".join(
105101
[
106102
f"{sys.executable}",
107-
f'"{template_path}{templates_repo}/validator.py"',
103+
f'"{templates}/validator.py"',
108104
"--netuid",
109105
str(netuid),
110106
"--subtensor.network",
111107
"local",
112108
"--subtensor.chain_endpoint",
113-
"ws://localhost:9945",
109+
"ws://localhost:9944",
114110
"--wallet.path",
115111
alice_wallet.path,
116112
"--wallet.name",

tests/e2e_tests/test_root_set_weights.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
wait_epoch,
77
sudo_set_hyperparameter_values,
88
)
9-
from tests.e2e_tests.utils.e2e_test_utils import (
10-
template_path,
11-
templates_repo,
12-
)
139

1410
FAST_BLOCKS_SPEEDUP_FACTOR = 5
1511

@@ -34,7 +30,13 @@
3430

3531

3632
@pytest.mark.asyncio
37-
async def test_root_reg_hyperparams(local_chain, subtensor, alice_wallet, bob_wallet):
33+
async def test_root_reg_hyperparams(
34+
local_chain,
35+
subtensor,
36+
templates,
37+
alice_wallet,
38+
bob_wallet,
39+
):
3840
"""
3941
Test root weights and hyperparameters in the Subtensor network.
4042
@@ -86,13 +88,13 @@ async def test_root_reg_hyperparams(local_chain, subtensor, alice_wallet, bob_wa
8688
cmd = " ".join(
8789
[
8890
f"{sys.executable}",
89-
f'"{template_path}{templates_repo}/validator.py"',
91+
f'"{templates}/validator.py"',
9092
"--netuid",
9193
str(netuid),
9294
"--subtensor.network",
9395
"local",
9496
"--subtensor.chain_endpoint",
95-
"ws://localhost:9945",
97+
"ws://localhost:9944",
9698
"--wallet.path",
9799
alice_wallet.path,
98100
"--wallet.name",

tests/e2e_tests/test_subtensor_functions.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
sudo_set_admin_utils,
99
wait_epoch,
1010
)
11-
from tests.e2e_tests.utils.e2e_test_utils import (
12-
template_path,
13-
templates_repo,
14-
)
1511

1612
"""
1713
Verifies:
@@ -35,7 +31,7 @@
3531

3632

3733
@pytest.mark.asyncio
38-
async def test_subtensor_extrinsics(subtensor, alice_wallet, bob_wallet):
34+
async def test_subtensor_extrinsics(subtensor, templates, alice_wallet, bob_wallet):
3935
"""
4036
Tests subtensor extrinsics
4137
@@ -163,13 +159,13 @@ async def test_subtensor_extrinsics(subtensor, alice_wallet, bob_wallet):
163159
cmd = " ".join(
164160
[
165161
f"{sys.executable}",
166-
f'"{template_path}{templates_repo}/validator.py"',
162+
f'"{templates}/validator.py"',
167163
"--netuid",
168164
str(netuid),
169165
"--subtensor.network",
170166
"local",
171167
"--subtensor.chain_endpoint",
172-
"ws://localhost:9945",
168+
"ws://localhost:9944",
173169
"--wallet.path",
174170
alice_wallet.path,
175171
"--wallet.name",

tests/e2e_tests/utils/e2e_test_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ def clone_or_update_templates(specific_commit=None):
7373

7474
os.chdir(cwd)
7575

76-
return install_dir + templates_repo + "/"
76+
return install_dir + templates_repo
7777

7878

7979
def install_templates(install_dir):
80-
subprocess.check_call([sys.executable, "-m", "pip", "install", "."])
80+
subprocess.check_call([sys.executable, "-m", "pip", "install", "-e", "."])
8181

8282

8383
def uninstall_templates(install_dir):

0 commit comments

Comments
 (0)