Collection<PsiElement> (@NotNull PsiElement element) { final PyFunction sourceFunction = PsiTreeUtil.getParentOfType(element, PyFunction.class); final PyClass source = PsiTreeUtil.getParentOfType(element, PyClass.class); if (sourceFunction == null && source == null) return Collections.emptySet(); List<Pair<? extends PsiNamedElement, Integer>> testsWithWeights = new ArrayList<>(); final List<Pair<String, Integer>> possibleNames = new ArrayList<>(); if (source != null) { possibleNames.addAll(TestFinderHelper.collectPossibleClassNamesWithWeights(source.getName())); } if (sourceFunction != null) { possibleNames.addAll(TestFinderHelper.collectPossibleClassNamesWithWeights(sourceFunction.getName())); } for (final Pair<String, Integer> eachNameWithWeight : possibleNames) { for (PyClass eachClass : PyClassNameIndex.find(eachNameWithWeight.first, element.getProject(), GlobalSearchScope.projectScope(element.getProject()))) { if (!PythonUnitTestDetectorsBasedOnSettings.isTestClass(eachClass, ThreeState.NO, null)) { testsWithWeights.add(new Pair<PsiNamedElement, Integer>(eachClass, eachNameWithWeight.second)); } } for (PyFunction function : PyFunctionNameIndex.find(eachNameWithWeight.first, element.getProject(), GlobalSearchScope.projectScope(element.getProject()))) { if (!PythonUnitTestDetectorsBasedOnSettings.isTestFunction(function, ThreeState.UNSURE, null)) { testsWithWeights.add(new Pair<PsiNamedElement, Integer>(function, eachNameWithWeight.second)); } } } return TestFinderHelper.getSortedElements(testsWithWeights, false); }