For Python, rule S3415 is incorrect. The order of arguments to self.assertEqual in unittest is expected, actual. The rule states incorrectly that the order is actual, expected for unittest. This results in false positives for instances where the first argument to assertEqual is a literal. SonarQube Cloud is the instance that reported this.
I’ve come to realize that it is PyCharm doing its own thing - reporting expected as the first parameter and actual as second parameter in test results.
Some minor feedback: I do think that creating a rule based on examples in this case seems to lack solid footing particularly since unittest defines the arguments to assertEqual as (first, second) - not (actual, expected) - in their documentation.
I see your point, however, it might make sense to still recommend an order that is closely aligned as possible to the usual conventions in other libraries (principle of least surprise). I’m going to flag this for the team in charge of rule definitions in case they want to review it.
As this rule was slightly too strict and trying to enforce a convention many didn’t like, its behavior was revisited in release 5.28.0.35681. Now, this rule only raises an issue if assertion orders are mixed within a file, allowing you to use whichever convention you prefer as long as you stay consistent.
Thanks again for your report and for helping us improve our products!