Skip to content

Commit 6a9c5a6

Browse files
committed
rebase and udpate angry mutants
1 parent a7b8712 commit 6a9c5a6

File tree

3 files changed

+83
-8
lines changed

3 files changed

+83
-8
lines changed

tests/json_infra/conftest.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from typing import Final, Optional, Set
66

77
import git
8+
import pytest
89
import requests_cache
910
from _pytest.config import Config
1011
from _pytest.config.argparsing import Parser
@@ -215,6 +216,14 @@ def __exit__(
215216

216217

217218
def pytest_sessionstart(session: Session) -> None: # noqa: U100
219+
# used for mutmut mutation testing
220+
all_fixtures_ready = all(
221+
os.path.exists(props["fixture_path"])
222+
for props in TEST_FIXTURES.values()
223+
)
224+
if os.environ.get("MUTANT_UNDER_TEST") and all_fixtures_ready:
225+
return
226+
218227
if get_xdist_worker_id(session) != "master":
219228
return
220229

@@ -250,8 +259,17 @@ def pytest_sessionfinish(
250259
if get_xdist_worker_id(session) != "master":
251260
return
252261

253-
lock_file = session.stash[fixture_lock]
254-
session.stash[fixture_lock] = None
262+
if fixture_lock in session.stash:
263+
lock_file = session.stash[fixture_lock]
264+
session.stash[fixture_lock] = None
265+
266+
assert lock_file is not None
267+
lock_file.release()
268+
255269

256-
assert lock_file is not None
257-
lock_file.release()
270+
# This is required explicitly becuase when the source does not have any
271+
# mutable code, mutmut does not run the forced fail condition.
272+
@pytest.fixture(autouse=True)
273+
def mutmut_forced_fail() -> None:
274+
if os.environ.get("MUTANT_UNDER_TEST") == "fail":
275+
pytest.fail("Forced fail for mutmut sanity check")

tests/json_infra/test_blockchain_tests.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Callable, Dict
1+
from typing import Any, Callable, Dict
22

33
import pytest
44

@@ -10,13 +10,41 @@
1010
run_blockchain_st_test,
1111
)
1212

13+
# angry mutant cases are tests that cannot be run for mutation testing
14+
ANGRY_MUTANT_CASES = (
15+
"Callcode1024OOG",
16+
"Call1024OOG",
17+
"CallRecursiveBombPreCall",
18+
"CallRecursiveBomb1",
19+
"ABAcalls2",
20+
"CallRecursiveBombLog2",
21+
"CallRecursiveBomb0",
22+
"ABAcalls1",
23+
"CallRecursiveBomb2",
24+
"CallRecursiveBombLog"
25+
)
26+
27+
28+
def is_angry_mutant(test_case: Any) -> bool:
29+
return any(case in str(test_case) for case in ANGRY_MUTANT_CASES)
30+
31+
32+
def get_marked_blockchain_test_cases(fork_name: str):
33+
"""Get blockchain test cases with angry mutant marking for the given fork."""
34+
return [
35+
pytest.param(tc, marks=pytest.mark.angry_mutant)
36+
if is_angry_mutant(tc)
37+
else tc
38+
for tc in fetch_blockchain_tests(fork_name)
39+
]
40+
1341

1442
def _generate_test_function(fork_name: str) -> Callable:
1543
@pytest.mark.fork(fork_name)
1644
@pytest.mark.json_blockchain_tests
1745
@pytest.mark.parametrize(
1846
"blockchain_test_case",
19-
fetch_blockchain_tests(fork_name),
47+
get_marked_blockchain_test_cases(fork_name),
2048
ids=idfn,
2149
)
2250
def test_func(blockchain_test_case: Dict) -> None:

tests/json_infra/test_state_tests.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,47 @@
1-
from typing import Callable, Dict
1+
from typing import Any, Callable, Dict
22

33
import pytest
44

55
from . import FORKS
66
from .helpers.load_state_tests import fetch_state_tests, idfn, run_state_test
77

8+
# angry mutant cases are tests that cannot be run for mutation testing
9+
ANGRY_MUTANT_CASES = (
10+
"Callcode1024OOG",
11+
"Call1024OOG",
12+
"CallRecursiveBombPreCall",
13+
"CallRecursiveBombLog2",
14+
"CallRecursiveBomb2",
15+
"ABAcalls1",
16+
"CallRecursiveBomb0_OOG_atMaxCallDepth",
17+
"ABAcalls2",
18+
"CallRecursiveBomb0",
19+
"CallRecursiveBomb1",
20+
"CallRecursiveBombLog"
21+
)
22+
23+
24+
def is_angry_mutant(test_case: Any) -> bool:
25+
return any(case in str(test_case) for case in ANGRY_MUTANT_CASES)
26+
27+
28+
def get_marked_state_test_cases(fork_name: str):
29+
"""Get state test cases with angry mutant marking for the given fork."""
30+
return [
31+
pytest.param(tc, marks=pytest.mark.angry_mutant)
32+
if is_angry_mutant(tc)
33+
else tc
34+
for tc in fetch_state_tests(fork_name)
35+
]
36+
837

938
def _generate_test_function(fork_name: str) -> Callable:
1039
@pytest.mark.fork(fork_name)
1140
@pytest.mark.evm_tools
1241
@pytest.mark.json_state_tests
1342
@pytest.mark.parametrize(
1443
"state_test_case",
15-
fetch_state_tests(fork_name),
44+
get_marked_state_test_cases(fork_name),
1645
ids=idfn,
1746
)
1847
def test_func(state_test_case: Dict) -> None:

0 commit comments

Comments
 (0)