void () { final String libraryWithTodoName = "numbers.py"; runWithAdditionalFileInLibDir( libraryWithTodoName, "# TODO: this should be updated", (__) -> { final List<VirtualFile> indexFiles = getTodoFiles(myFixture.getProject()); // project file in the TodoIndex assertTrue(indexFiles.stream().anyMatch((x) -> "a.py".equals(x.getName()))); // no library files in the TodoIndex assertFalse(indexFiles.stream().anyMatch((x) -> libraryWithTodoName.equals(x.getName()))); final Module module = myFixture.getModule(); final Sdk sdk = PythonSdkUtil.findPythonSdk(module); final VirtualFile libDir = PySearchUtilBase.findLibDir(sdk); ModuleRootModificationUtil.addContentRoot(module, libDir); try { // mock sdk doesn't fire events FileBasedIndex.getInstance().requestRebuild(TodoIndex.NAME); PlatformTestUtil.dispatchAllEventsInIdeEventQueue(); FileBasedIndex.getInstance().ensureUpToDate(TodoIndex.NAME, myFixture.getProject(), null); final List<VirtualFile> updatedIndexFiles = getTodoFiles(myFixture.getProject()); // but if it is added as a content root - it should be in the TodoIndex assertTrue(updatedIndexFiles.stream().anyMatch((x) -> libraryWithTodoName.equals(x.getName()))); } finally { ModuleRootModificationUtil.updateModel(module, model -> { for (ContentEntry entry : model.getContentEntries()) { if (libDir.equals(entry.getFile())) { model.removeContentEntry(entry); } } }); } } ); }