Skip to content

Commit 6f69f4a

Browse files
tests: separate templates fixture
1 parent 6d17860 commit 6f69f4a

File tree

7 files changed

+24
-40
lines changed

7 files changed

+24
-40
lines changed

tests/e2e_tests/conftest.py

Lines changed: 12 additions & 8 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):
@@ -102,8 +95,19 @@ 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

tests/e2e_tests/test_axon.py

Lines changed: 2 additions & 6 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,7 +49,7 @@ 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",

tests/e2e_tests/test_dendrite.py

Lines changed: 2 additions & 6 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,7 +108,7 @@ 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",

tests/e2e_tests/test_incentive.py

Lines changed: 3 additions & 7 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,7 +71,7 @@ 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",
@@ -104,7 +100,7 @@ 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",

tests/e2e_tests/test_root_set_weights.py

Lines changed: 2 additions & 6 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,7 @@
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(local_chain, subtensor, templates, alice_wallet, bob_wallet):
3834
"""
3935
Test root weights and hyperparameters in the Subtensor network.
4036
@@ -86,7 +82,7 @@ async def test_root_reg_hyperparams(local_chain, subtensor, alice_wallet, bob_wa
8682
cmd = " ".join(
8783
[
8884
f"{sys.executable}",
89-
f'"{template_path}{templates_repo}/validator.py"',
85+
f'"{templates}/validator.py"',
9086
"--netuid",
9187
str(netuid),
9288
"--subtensor.network",

tests/e2e_tests/test_subtensor_functions.py

Lines changed: 2 additions & 6 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,7 +159,7 @@ 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",

tests/e2e_tests/utils/e2e_test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ 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):

0 commit comments

Comments
 (0)