I know this problem very well and it really is quite a hassle to train it all the way to mega only for it to stumble with a bad talent at the top level. for me I have had to hatch pets time after time because I kept getting talents that I did not want. it was only recently after half a dozen unsuccessful hatches that I finally get a patch to emerge with the ideal talents I desire ( mainly healing and global resist talents).
my pet basically acts as my backup in a fight now providing my a much needed heal in a critical moment or their global defense saves me from a potentially fatal attack from the enemy.
the best thing you can do is to try and find a fellow wizard with a pet with all the ideal talents you want to continue to hatch with that same pet every time until you get a pet with all the ideal talents and at that point the likelihood of it failing at mega is very low.
this is what I had to do. usually I only train to adult and if any talent I want does not emerge by that point then I will give up on that pet and try again with the pet I used to hatch before.
right now my buddy dragon has dragonblade, fairy, and global resist.
so I get an attack buff, a heal, and global defense which is a solid pet in my book
It depends on what you consider a fail. You have not provided any information about your pet(s), which makes it a bit difficult to give you a better answer.
For me, I train my pets to adult or ancient. If I don't have my top two talents by ancient, I hatch again. I don't take my pets to mega unless I'm on a hot streak.
If you get most of what you want by epic, then stop there for the time being. Wait for test realm, and you can train whatever pets you have to mega there, and you can see their talents before you decide whether or not to train them in live.