forked from neonlabsorg/neon-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
95 lines (82 loc) · 3 KB
/
Copy pathconftest.py
File metadata and controls
95 lines (82 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import os
import json
import pathlib
import typing as tp
from dataclasses import dataclass
from _pytest.config import Config
from _pytest.runner import runtestprotocol
import clickfile
pytest_plugins = ["ui.plugins.browser"]
@dataclass
class EnvironmentConfig:
evm_loader: str
proxy_url: str
solana_url: str
faucet_url: str
network_id: int
operator_neon_rewards_address: tp.List[str]
spl_neon_mint: str
neon_erc20wrapper_address: str
operator_keys: tp.List[str]
use_bank: bool
eth_bank_account: str
account_seed_version: str = "\3"
def pytest_addoption(parser):
parser.addoption(
"--network", action="store", default="night-stand", help="Which stand use"
)
parser.addoption(
"--make-report",
action="store_true",
default=False,
help="Store tests result to file",
)
parser.addoption(
"--envs", action="store", default="envs.json", help="Filename with environments"
)
def pytest_sessionstart(session):
"""Hook for clearing the error log used by the Slack notifications utility"""
path = pathlib.Path(f"{clickfile.CMD_ERROR_LOG}")
if path.exists():
path.unlink()
def pytest_runtest_protocol(item, nextitem):
ihook = item.ihook
ihook.pytest_runtest_logstart(nodeid=item.nodeid, location=item.location)
reports = runtestprotocol(item, nextitem=nextitem)
ihook.pytest_runtest_logfinish(nodeid=item.nodeid, location=item.location)
if item.config.getoption("--make-report"):
path = pathlib.Path(f"{clickfile.CMD_ERROR_LOG}")
with path.open("a") as fd:
for report in reports:
if report.when == "call" and report.outcome == "failed":
fd.write(f"`{report.outcome.upper()}` {item.nodeid}\n")
return True
def pytest_configure(config: Config):
network_name = config.getoption("--network")
envs_file = config.getoption("--envs")
with open(pathlib.Path().parent.parent / envs_file, "r+") as f:
environments = json.load(f)
assert (
network_name in environments
), f"Environment {network_name} doesn't exist in envs.json"
env = environments[network_name]
if network_name == "devnet":
if "SOLANA_URL" in os.environ and os.environ["SOLANA_URL"]:
env["solana_url"] = os.environ.get("SOLANA_URL")
if "PROXY_URL" in os.environ and os.environ["PROXY_URL"]:
env["proxy_url"] = os.environ.get("PROXY_URL")
if "use_bank" not in env:
env["use_bank"] = False
if "eth_bank_account" not in env:
env["eth_bank_account"] = ""
if network_name == "aws":
env["solana_url"] = env["solana_url"].replace(
"<solana_ip>", os.environ.get("SOLANA_IP")
)
env["proxy_url"] = env["proxy_url"].replace(
"<proxy_ip>", os.environ.get("PROXY_IP")
)
env["faucet_url"] = env["faucet_url"].replace(
"<proxy_ip>", os.environ.get("PROXY_IP")
)
config.environment = EnvironmentConfig(**env)