Actually you can only request a context that is backward compatible to the specified version, but you cannot prevent the driver from creating a higher version.
Even if you could request a version 3.1 context, all the functionalilty up to OpenGL 4.5 could by accessed from 3.1 via ARB extensions, so you cannot test that the program would run on hardware that supports only pure OpenGL 3.1.
Good point. However, the takeaway is that you can do development for a back version of OpenGL by explicitly creating a context that supports that version, but yes you should still do regression testing on a driver/GPU that is limited to the version your testing.
For example, when I create a GL 3.1 context on my Geforce 550Ti I still have all the extensions up to GL 4.5 which means that despite the low version number all the functionality of later GL versions is present. That is useless for testing.