-
Notifications
You must be signed in to change notification settings - Fork 0
/
cypress-bdd-stats.py
executable file
·66 lines (49 loc) · 2.56 KB
/
cypress-bdd-stats.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
#!/opt/homebrew/bin/python3
import os
import re
import argparse
def count_disabled_tests(feature_directory='./'):
total_tests = 0
disabled_tests = 0
for root, _, files in os.walk(feature_directory):
for file in files:
if file.endswith(".feature"):
with open(os.path.join(root, file), "r") as f:
content = f.read()
# Use regular expression to find scenarios and scenario outlines that are disabled
disabled_scenarios = re.findall(r"@disabled\s*(?:\n\s*@.*?)*\n\s*(Scenario Outline:|Scenario:)", content)
# Count the total number of scenarios and scenario outlines in the feature file
total_tests += len(re.findall(r"Scenario Outline:|Scenario:", content))
# If the scenario is a Scenario Outline, count the number of examples
if "Scenario Outline:" in content:
example_count = len(re.findall(r"Examples:", content))
disabled_tests += example_count
# Count individual disabled scenarios
disabled_tests += len(disabled_scenarios)
enabled_tests = total_tests - disabled_tests
disabled_percentage = (disabled_tests / total_tests) * 100 if total_tests > 0 else 0
enabled_percentage = (enabled_tests / total_tests) * 100 if total_tests > 0 else 0
return total_tests, disabled_tests, enabled_tests, disabled_percentage, enabled_percentage
def main():
parser = argparse.ArgumentParser(description="Count disabled and enabled tests in BDD feature files.")
parser.add_argument("directories", nargs="*", default=["./"], help="List of directories to search for feature files.")
args = parser.parse_args()
total_total = 0
total_disabled = 0
total_enabled = 0
for directory in args.directories:
total, disabled, enabled, disabled_percentage, enabled_percentage = count_disabled_tests(directory)
total_total += total
total_disabled += disabled
total_enabled += enabled
print(f"Directory: {directory}")
print(f"Disabled: {disabled} ({disabled_percentage:.2f}%)")
print(f"Enabled: {enabled} ({enabled_percentage:.2f}%)")
print(f"Total: {total}")
print()
print("Overall Total:")
print(f"Disabled: {total_disabled} ({(total_disabled / total_total * 100):.2f}%)")
print(f"Enabled: {total_enabled} ({(total_enabled / total_total * 100):.2f}%)")
print(f"Total: {total_total}")
if __name__ == "__main__":
main()