void (@Nullable String destination, @Nullable String errorMessage) { final PyFunction function = assertInstanceOf(myFixture.getElementAtCaret(), PyFunction.class); if (destination == null) { destination = PyPsiUtils.getContainingFilePath(function); } else { final VirtualFile srcRoot = ModuleRootManager.getInstance(myFixture.getModule()).getSourceRoots()[0]; destination = FileUtil.join(srcRoot.getPath(), destination); } assertNotNull(destination); final String finalDestination = destination; try { if (function.getContainingClass() != null) { new PyMakeMethodTopLevelProcessor(function, finalDestination).run(); } else { new PyMakeLocalFunctionTopLevelProcessor(function, finalDestination).run(); } } catch (IncorrectOperationException e) { if (errorMessage == null) { fail("Refactoring failed unexpectedly with message: " + e.getMessage()); } assertEquals(errorMessage, e.getMessage()); } }