From 0e4532f8e7d4bf29098f3e1314e3d45e631a4549 Mon Sep 17 00:00:00 2001 From: Mateusz Mandera Date: Fri, 29 Sep 2023 17:03:18 +0200 Subject: [PATCH] semgrep: Add rule to specify tick kwarg on time_machine.travel() calls. Letting the clock tick without a reason introduces the possibility of nondeterministic test failures depending on the execution time. The default value when not specified is tick=True, which makes it easy to miss. The rule doesn't prohibit setting tick=True, as perhaps there will be tests wanting to use that feature on purpose, but such a test should explicitly set it to make the intent clear. --- tools/semgrep-py.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/semgrep-py.yml b/tools/semgrep-py.yml index 126d468fbc..c8a39fec2a 100644 --- a/tools/semgrep-py.yml +++ b/tools/semgrep-py.yml @@ -17,6 +17,15 @@ rules: include: - zerver/views/ + - id: time-machine-travel-specify-tick + patterns: + - pattern: time_machine.travel(...) + - pattern-not: time_machine.travel(..., tick=..., ...) + message: | + Specify tick kwarg value for time_machine.travel(). Most cases will want to use False. + languages: [python] + severity: ERROR + - id: limit-message-filter patterns: - pattern: Message.objects.filter(...)