From the comments, we have to address this question for high school.
The energy of a gas can be written as a sum of kinetic energy, describing the energy due to the motion, and potential energy, that describe the interactions between the molecules of the gas:
$$ U = U_{kin} + U_{pot} $$
For calculate the heat capacity at constant volume, we have to derive respect to the temperature, keeping the volume constant.
$$ c_{m, V} = \frac{1}{n} \frac{d\langle U \rangle}{dT} = \frac{1}{n} (\frac{d\langle U_{kin} \rangle }{dT} + \frac{d\langle U_{pot}\rangle}{dT}) $$
Where $c_{m, V} $ is the molar heat capacity at constant volume, $\langle... \rangle$ is the mean and $n$ is the number of moles.
The equipartition of the energy dictates that the mean kinetic energy is: $\langle U_{kin} \rangle = \frac{nfRT}{2} $, where $f$ is the number of degrees of freedom, $R$ the gas constant and $n$ the number of moles. Then:
$$ c_{m, V} = \frac{1}{n} \frac{d\langle U \rangle}{dT} = \frac{fR}{2} + \frac{1}{n}\frac{d\langle U_{pot}\rangle}{dT} $$
So the point is the potential energy. The relation written in the question is valid for energy that is quadratic in the proper variables. The equipartition, clearly, not only applies on ideal gas (where the potential energy is zero), but also in all situations where the potential energy has the same form of the kinetic energy. The potential energy for real gases don't have the right form.
In general heat capacity depends on temperature, using the equipartition the final result is independent from the temperature, because the average kinetic energy is linear on temperature. The potential energy introduce this dependence in the heat capacity, because the mean potential energy can be higher order on $T$.
The potential energy can be quadratic and so the equipartition holds, but when is not quadratic as i said the dependence of the temperature is different. In real gases the potential is not quadratic.