This paper investigates both theoretically and using finite elements the elastoplastic field induced by a pressurized spherical cavity expanding dynamically in an infinite medium modelled using the Gurson-Tvergaard-Needleman porous plasticity approach. The theoretical model, which assumes that the porosity is uniformly distributed in the material and the cavitation fields are self-similar, incorporates artificial viscous stresses into the original formulation of Cohen and Durban (2013b) to capture the shock waves that emerge at high cavitation velocities. The finite element calculations, performed in ABAQUS/Explicit (2013) using the Arbitrary Lagrangian Eulerian adaptive meshing available in the code, simulate the cavity expansion process in materials with uniform and non-uniform distributions of porosity. The finite element results show that the distribution of porosity has small influence on the cavitation velocity, as well as on the location of the shock wave, which are primarily determined by the cavity pressure and the average material properties. In contrast, it is shown that the intensity of the shock wave, evaluated based on the maximum value of the plastic strain rate within the shock, depends on the local material porosity. The ability of the theoretical model to reproduce the numerical results obtained for the various distributions of porosity used in this work is exposed and discussed.