-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpytest_assassin.py
77 lines (66 loc) · 2.25 KB
/
pytest_assassin.py
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
"This class allows the pytest to run in the terminal"
import ast
import inspect
import pytest
def pytest_addoption(parser):
""" Turns features on with "--assassin" option"""
group = parser.getgroup("assassin")
group.addoption("--assassin", action="store_true")
def pytest_report_header():
""" Executuion is run if assassin is presented in terminal """
# pylint: disable=no-member
if pytest.config.getoption("assassin"):
execution()
# def walk():
# directory = os.listdir("./")
# for object in directory:
# if object == "tests":
# walk = os.walk("tests")
# print("hi")
# elif object == "testing":
# os.walk("testing")
# else:
# print("Not a test folder")
def execution():
""" Checks for the instance of an assert and prints pass or fail """
testerFile = open("tests/test_new.py", "r")
nodes = [
item
for item in ast.parse(testerFile.read()).body
if isinstance(item, ast.FunctionDef)
]
for node in nodes:
items = [item for item in ast.parse(node).body]
for item in items:
if isinstance(item, ast.Assign):
pass
elif isinstance(item, ast.Expr):
pass
elif isinstance(item, ast.Assert):
print("Pass")
else:
print("Fail")
def pytest_collection_modifyitems(items):
""" Changes what tests are executed by removing those without an assert """
nick = []
for item in items[:]:
# itemz = inspect.getsource(item)
# print(inspect.isfunction(item))
funcItem = item.function
itemz = inspect.getsource(funcItem)
chicken = [item for item in ast.parse(itemz).body]
for itemt in chicken:
var = False
item1 = ast.parse(itemt).body
for i in item1:
if isinstance(i, ast.Assign):
pass
elif isinstance(i, ast.Expr):
pass
elif isinstance(i, ast.Assert):
var = True
break
if var is False:
print(itemt.name)
nick.append(itemt.name)
items.remove(item)