Since it's only for testing purpose, this code should do the job. Don't forget to install
https://github.com/ofek/bit first.
>>> from bit import Key
>>> key = Key()
>>> key.address
'1GCfsCqwdtM3BSxj1iXKRE4RpK4qMvZZQn'
>>> key.segwit_address
'3Gkt8rYpVuDKxCDM3dDHGUaaFEeANfqbQo'
I want to generate a P2SH address from the pubkey instead.
If you don't need any specific feature (e.g. timelock or multi-signature), you don't really need P2SH address.