PsiElement (PyClass clazz, Function<String, PyStatement> callback) { final PyFunction init = clazz.findMethodByName(PyNames.TESTCASE_SETUP_NAME, false, null); if (init != null) { return AddFieldQuickFix.appendToMethod(init, callback); } final PyFunctionBuilder builder = new PyFunctionBuilder(PyNames.TESTCASE_SETUP_NAME, clazz); builder.parameter(PyNames.CANONICAL_SELF); PyFunction setUp = builder.buildFunction(); final PyStatementList statements = clazz.getStatementList(); final PsiElement anchor = statements.getFirstChild(); setUp = (PyFunction)statements.addBefore(setUp, anchor); return AddFieldQuickFix.appendToMethod(setUp, callback); }