Skip to content

Commit 16c48d7

Browse files
maksim-grebeniuk-sonarsourcesonartech
authored andcommitted
SONARPY-2812 [S5899] NotDiscoverableTestMethodCheck should not keep it's state as a static field (#220)
GitOrigin-RevId: 1e0da1ba7c4d1c11a6378852c0f3d833832c1de7
1 parent 88b8dd0 commit 16c48d7

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

python-checks/src/main/java/org/sonar/python/checks/tests/NotDiscoverableTestMethodCheck.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@
4242
public class NotDiscoverableTestMethodCheck extends PythonSubscriptionCheck {
4343

4444
private static final String MESSAGE = "Rename this method so that it starts with \"test\" or remove this unused helper.";
45-
private static final Set<String> globalFixture = new HashSet<>();
45+
private final Set<String> globalFixture = new HashSet<>();
4646

4747
@Override
4848
public void initialize(Context context) {
49-
context.registerSyntaxNodeConsumer(Tree.Kind.FUNCDEF, ctx -> NotDiscoverableTestMethodCheck.lookForGlobalFixture((FunctionDef) ctx.syntaxNode()));
49+
context.registerSyntaxNodeConsumer(Tree.Kind.FUNCDEF, ctx -> lookForGlobalFixture((FunctionDef) ctx.syntaxNode()));
5050

5151
context.registerSyntaxNodeConsumer(Tree.Kind.CLASSDEF, ctx -> {
5252
ClassDef classDefinition = (ClassDef) ctx.syntaxNode();
@@ -73,7 +73,7 @@ public void initialize(Context context) {
7373
});
7474
}
7575

76-
private static void lookForGlobalFixture(FunctionDef functionDef) {
76+
private void lookForGlobalFixture(FunctionDef functionDef) {
7777
if (functionDef.isMethodDefinition()) {
7878
return;
7979
}
@@ -97,7 +97,7 @@ private static Set<String> getFixturesFromClass(ClassDef classDefinition) {
9797
.collect(Collectors.toSet());
9898
}
9999

100-
private static boolean isException(FunctionDef functionDef, Set<String> classFixtures) {
100+
private boolean isException(FunctionDef functionDef, Set<String> classFixtures) {
101101
String functionName = functionDef.name().name();
102102
return overrideExistingMethod(functionName) || functionName.startsWith("test") || isHelper(functionDef, classFixtures);
103103
}
@@ -127,7 +127,7 @@ private static boolean overrideExistingMethod(String functionName) {
127127
return UnittestUtils.allMethods().contains(functionName) || functionName.startsWith("_");
128128
}
129129

130-
private static boolean isHelper(FunctionDef functionDef, Set<String> currentClassFixture) {
130+
private boolean isHelper(FunctionDef functionDef, Set<String> currentClassFixture) {
131131
return Optional.ofNullable(TreeUtils.getFunctionSymbolFromDef(functionDef)).stream()
132132
.anyMatch(functionSymbol -> functionSymbol.hasDecorators() || !functionSymbol.parameters().stream()
133133
.map(FunctionSymbol.Parameter::name)

0 commit comments

Comments
 (0)