void () { PyElementGenerator generator = PyElementGenerator.getInstance(myFixture.getProject()); PyFunction function = generator.createPhysicalFromText(LanguageLevel.PYTHON27, PyFunction.class, "def foo(): print 1"); PyFunction function2 = generator.createPhysicalFromText(LanguageLevel.PYTHON27, PyFunction.class, "def foo(): print 2"); final PyStatementList list1 = function.getStatementList(); final PyStatementList list2 = function2.getStatementList(); WriteCommandAction.writeCommandAction(myFixture.getProject()).run(() -> list1.add(list2.getStatements()[0])); assertEquals("def foo():\n print 1\n print 2", function.getText()); }