Theoretically speaking, beryllium and magnesium does not give flame test because their atoms are comparatively smaller and the valance electrons are strongly attached to the nucleus. Therefore their ionisation energies are high, so they need large amount of energy for the excitation of their valence electrons to higher energy level which is usually not available in the Bunsen flame. So they do not impart any colour to the flame.
Now, comparing the atomic radius of lithium and magnesium, both have nearly same atomic radius due to diagonal relationship.($\ce{152}$ pm and $\ce{160}$ pm respectively). Since both of them nearly have same atomic radius, why is lithium imparting flame coloration(crimson red) while magnesium is not? Both of the metals has to be supplied equal amount of energy to excite the electron which the burner is not able to supply and thus flame test should fail in this case but this is not happening.
I don't understand despite the reasoning for beryllium not giving flame coloration is quite correct, wikipedia claims beryllium to give flame coloration(white).