Calculations of tearing mode stability in tokamaks split conveniently into an external region, where marginally stable ideal MHD is applicable, and a resonant layer around the rational surface where sophisticated kinetic physics is needed. These two regions are coupled by the stability parameter △'. Pressure and current perturbations localized around the rational surface alter the stability of tearing modes. Equations governing the changes in the external solution and △' are derived for arbitrary perturbations in axisymmetric toroidal geometry. The relationship of △' with and without pressure flattening is obtained analytically for four pressure flattening functions. Resistive MHD codes do not contain the appropriate layer physics and therefore cannot predict stability directly. They can, however, be used to calculate △'. Existing methods (Hamet al. 2012 Plasma Phys. Control. Fusion 54 025009) for extracting △' from resistive codes are unsatisfactory when there is a finite pressure gradient at the rational surface and favourable average curvature because of the Glasser stabilizing effect. To overcome this difficulty we introduce a specific pressure flattening function that allows the earlier approach to be used. The technique is first tested numerically in cylindrical geometry with an artificial favourable curvature. Its application to toroidal geometry is then demonstrated using the toroidal tokamak tearing mode stability code T7 (Fitzpatrick and et al. 1993 Nucl. Fusion 33 1533) which uses an approximate analytic equilibrium. The prospects for applying this approach to resistive MHD codes such as MARS-F (Liu et al. 2000 Phys. Plasmas 7 3681) which utilize a fully toroidal equilibrium are discussed.