boolean (@NotNull AbstractPythonLegacyTestRunConfiguration configuration, @NotNull ConfigurationContext context) { final Location location = context.getLocation(); if (location == null || !isAvailable(location)) return false; final PsiElement element = location.getPsiElement(); final PsiFileSystemItem file = element.getContainingFile(); if (file == null) return false; final VirtualFile virtualFile = element instanceof PsiDirectory ? ((PsiDirectory)element).getVirtualFile() : file.getVirtualFile(); if (virtualFile == null) return false; final PyFunction pyFunction = PsiTreeUtil.getParentOfType(element, PyFunction.class, false); final PyClass pyClass = PsiTreeUtil.getParentOfType(element, PyClass.class); final AbstractPythonLegacyTestRunConfiguration.TestType confType = configuration.getTestType(); final String workingDirectory = configuration.getWorkingDirectory(); if (element instanceof PsiDirectory) { final String path = ((PsiDirectory)element).getVirtualFile().getPath(); return confType == AbstractPythonLegacyTestRunConfiguration.TestType.TEST_FOLDER && path.equals(configuration.getFolderName()) || path.equals(new File(workingDirectory, configuration.getFolderName()).getAbsolutePath()); } final String scriptName = configuration.getScriptName(); final String path = virtualFile.getPath(); final boolean isTestFileEquals = scriptName.equals(path) || path.equals(new File(workingDirectory, scriptName).getAbsolutePath()); if (pyFunction != null) { final String methodName = configuration.getMethodName(); if (pyFunction.getContainingClass() == null) { return confType == AbstractPythonLegacyTestRunConfiguration.TestType.TEST_FUNCTION && methodName.equals(pyFunction.getName()) && isTestFileEquals; } else { final String className = configuration.getClassName(); return confType == AbstractPythonLegacyTestRunConfiguration.TestType.TEST_METHOD && methodName.equals(pyFunction.getName()) && pyClass != null && className.equals(pyClass.getName()) && isTestFileEquals; } } if (pyClass != null) { final String className = configuration.getClassName(); return confType == AbstractPythonLegacyTestRunConfiguration.TestType.TEST_CLASS && className.equals(pyClass.getName()) && isTestFileEquals; } return confType == AbstractPythonLegacyTestRunConfiguration.TestType.TEST_SCRIPT && isTestFileEquals; }