PsiElement () { myFixture.configureByFile("resolve/" + getTestName(false) + ".py"); final PsiFile psiFile = myFixture.getFile(); final int markerOffset = findMarkerOffset(psiFile); final InjectedLanguageManager manager = InjectedLanguageManager.getInstance(myFixture.getProject()); final PsiElement injectedElement = manager.findInjectedElementAt(psiFile, markerOffset); assertNotNull("no injected element found at <ref> position", injectedElement); PsiReference reference = null; final PyReferenceOwner referenceOwner = PsiTreeUtil.getParentOfType(injectedElement, PyReferenceOwner.class); if (referenceOwner != null) { reference = referenceOwner.getReference(); } assertNotNull("no reference found at <ref> position", reference); return reference.resolve(); }