Skip to content

Commit 2b01a09

Browse files
chore: add semgrep test correctness rules and fix teardown
1 parent 32e22a8 commit 2b01a09

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

payments/payment_gateways/doctype/mpesa_settings/test_mpesa_settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def setUp(self):
4545
)
4646

4747
def tearDown(self):
48-
frappe.db.rollback()
48+
super().tearDown()
4949
for x in frappe.db.get_all("POS Opening Entry"):
5050
frappe.get_doc("POS Opening Entry", x.name).cancel().delete()
5151
frappe.db.sql("delete from `tabMpesa Settings`")

semgrep/test-correctness.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
rules:
2+
- id: Dont-commit
3+
pattern: frappe.db.commit()
4+
message: Commiting inside test breaks idempotency.
5+
languages: [python]
6+
severity: ERROR
7+
- id: Implicit-commit
8+
pattern: frappe.db.truncate()
9+
message: DB truncation does implict commit which breaks test idempotency.
10+
languages: [python]
11+
severity: ERROR
12+
- id: Dont-override-teardown
13+
patterns:
14+
- pattern: |
15+
def tearDown(...):
16+
...
17+
- pattern-not: |
18+
def tearDown(...):
19+
...
20+
super().tearDown()
21+
...
22+
message: PaymentsTestSuite forces rollback on each tearDown, which ensures idempotency. Don't override tearDown.
23+
languages: [python]
24+
severity: ERROR

0 commit comments

Comments
 (0)