python unittest-method-names rule

196 views
Skip to first unread message

liav....@gmail.com

unread,
Dec 15, 2015, 1:18:07 PM12/15/15
to SonarQube
Hi. We're running Sonar against our production code base and commonly use Django's test framework as well as Python's standard library unittest package. Both of these packages follow JUnit's naming convention, which is camel case, rather than the more common Python snake case standard. This creates a lot of noisy alerts for every `setUp`/`setUpClass`/`setUpModule`/`tearDown` etc in the module. Assertions are also camel-cased, so you have the same problem if you write a custom assertion method.

I'd just started familiarizing myself with the sonar docs and xpath, and came up with a query that finds setUp methods, when I came across the directive in the docs to visit here and publicly propose the rule.

Also, if anybody has suggestions on how to finish implementing this, that would be great. As I said, I have figured out query selectors for function defs that match 'setUp*'/'tearDown*'/'assert*', but I how do you specify that a rule only applies in files whose name matches `test*.py`?

Best,
Liav.

Pierre-Yves Nicolas

unread,
Dec 18, 2015, 7:27:15 AM12/18/15
to liav....@gmail.com, SonarQube
Hi,

The common approach is to define which files are tests with the "sonar.tests" property.

SonarQube excludes test files from the set of sources.
Test files are not analysed and no issue is therefore raised in those files.

If you want to analyse those files, another approach may be to exclude them for certain rules.

Regards,
Pierre-Yves


--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/a7ba9677-9241-4bca-a266-4d68d2806717%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages