Skip to content

Commit 61aa127

Browse files
committed
use pytest for brownie integration test in CI
1 parent 6c92aae commit 61aa127

File tree

4 files changed

+50
-35
lines changed

4 files changed

+50
-35
lines changed

.github/workflows/ci.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ jobs:
1818
fail-fast: false
1919
matrix:
2020
os: ["ubuntu-latest", "windows-2022"]
21-
type: ["brownie", "buidler", "dapp", "embark", "etherlime", "hardhat", "solc", "truffle", "waffle", "foundry", "standard"]
21+
type: ["brownie"]
22+
# "buidler", "dapp", "embark", "etherlime", "hardhat", "solc", "truffle", "waffle", "foundry", "standard"]
2223
exclude:
2324
# Currently broken, tries to pull git:// which is blocked by GH
2425
- type: embark
@@ -73,3 +74,4 @@ jobs:
7374
shell: bash
7475
run: |
7576
bash "scripts/ci_test_${TEST_TYPE}.sh"
77+
pytest -k $TEST_TYPE

scripts/ci_test_brownie.sh

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/usr/bin/env bash
22

33
pip install eth-brownie
4-
brownie bake token
5-
cd token || exit 255
4+
# brownie bake token
5+
# cd token || exit 255
66

7-
crytic-compile . --compile-force-framework Brownie
7+
# crytic-compile . --compile-force-framework Brownie
88

9-
if [ $? -ne 0 ]
10-
then
11-
echo "Brownie test failed"
12-
exit 255
13-
fi
9+
# if [ $? -ne 0 ]
10+
# then
11+
# echo "Brownie test failed"
12+
# exit 255
13+
# fi

tests/conftest.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import shutil
2+
import tempfile
3+
import subprocess
4+
import pytest
5+
from typing import List
6+
7+
@pytest.fixture
8+
def make_tmpdir():
9+
with tempfile.TemporaryDirectory() as tmpdirname:
10+
yield tmpdirname
11+
12+
13+
import logging
14+
LOGGER = logging.getLogger(__name__)
15+
16+
@pytest.fixture
17+
def run_command():
18+
def _run(command: List[str], cwd: str) -> int:
19+
executable = shutil.which(command[0])
20+
assert executable
21+
process = subprocess.run(
22+
command,
23+
stdout=subprocess.PIPE,
24+
stderr=subprocess.PIPE,
25+
executable=executable,
26+
cwd=cwd,
27+
check=True
28+
)
29+
LOGGER.info(process.stdout.decode("utf-8"))
30+
LOGGER.error(process.stderr.decode("utf-8"))
31+
return process.returncode
32+
return _run

tests/test_brownie.py

+7-26
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,19 @@
11
import os
22
import shutil
3-
import tempfile
4-
import subprocess
53
import pytest
6-
from typing import List
7-
8-
# cmd = [sys.executable, "-m", "pip", "install", "eth-brownie"]
9-
10-
import logging
11-
LOGGER = logging.getLogger(__name__)
12-
13-
def run(command: List[str], cwd: str) -> int:
14-
process = subprocess.run(
15-
command,
16-
stdout=subprocess.PIPE,
17-
stderr=subprocess.PIPE,
18-
executable=shutil.which(command[0]),
19-
cwd=cwd,
20-
check=True
21-
)
22-
LOGGER.info(process.stdout.decode("utf-8"))
23-
LOGGER.error(process.stderr.decode("utf-8"))
24-
return process.returncode
254

265
brownie_available = shutil.which("brownie") is not None
276
@pytest.mark.skip_if(not brownie_available)
28-
def test_brownie():
7+
def test_brownie(make_tmpdir, run_command):
8+
tmpdirname = make_tmpdir
9+
2910
initialize = ["brownie", "bake", "token"]
3011
test = ["crytic-compile", ".", "--compile-force-framework", "brownie"]
3112

32-
with tempfile.TemporaryDirectory() as tmpdirname:
33-
34-
run(initialize, tmpdirname)
13+
run_command(initialize, tmpdirname)
14+
project_dir = os.path.join(tmpdirname,"token")
15+
assert os.path.isdir(project_dir)
16+
assert run_command(test, project_dir) == 0
3517

36-
run(test,os.path.join(tmpdirname,"token")) == 0
3718

3819

0 commit comments

Comments
 (0)