void () { myFixture.copyDirectoryToProject("bothForeignAndSourceRootImportResultsReturned", ""); VirtualFile vf = myFixture.findFileInTempDir("ext/m1.py"); runWithSourceRoots(Lists.newArrayList(myFixture.findFileInTempDir("root")), () -> { final PsiFile extSource = myFixture.getPsiManager().findFile(vf); PyImportResolver foreignResolver = (name, context, withRoots) -> name.toString().equals("m1") ? extSource : null; PyImportResolver.EP_NAME.getPoint().registerExtension(foreignResolver, getTestRootDisposable()); final PsiFile psiFile = myFixture.configureByFile("a.py"); final PsiReference ref = PyResolveTestCase.findReferenceByMarker(psiFile); assertInstanceOf(ref, PsiPolyVariantReference.class); final List<PsiElement> elements = PyUtil.multiResolveTopPriority((PsiPolyVariantReference)ref); assertEquals(2, elements.size()); final Set<String> parentNames = elements.stream() .filter(e -> e instanceof PyFile) .map(e -> ((PyFile)e).getVirtualFile().getParent().getName()).collect(Collectors.toSet()); assertContainsElements(parentNames, "root", "ext"); }); }