Wheel bearings vary widely in quality, and it is probably financially prudent to buy the one your mechanic will sell you, unless you are a gambler. Personally, I wouldn't trust a $40 hub assembly any farther than I can throw a '99 Cutlass, especially if it's an application for a car with ABS, which makes a significant difference in the price of the part. The reason I say it may be financially prudent to buy from your mechanic is because if something goes wrong with the wheel bearing, like it starts making noise within a couple months (remember, quality varies widely with hub assemblies), you have your mechanic's warranty to fall back on. Otherwise, you will be buying another wheel bearing and paying to have it installed all over again. One of the reasons other than what others already mentioned for mechanics to mark up parts is in case they have to "eat" the job a second time around if they get a defective part, which happens from time to time.
Quality wise, I have had the best luck with hub assemblies from CarQuest and NAPA and the worst luck with Advance Auto Parts I never really tried the other cheapo stores like O'Reilly or AutoZone since I got tired of replacing stuff for free. This is a type of part where you truly get what you pay for.