The first thing that you need to understand is the laws of your locality, state or country that may bear on the situation. The second thing to understand are the rules and by-laws of whatever professional organizations the mechanic or shop belong to. The third thing is to understand the protections in place when you pay with a credit card... you do ALWAYS pay your mechanic with a credit card, right? Why do you think there's often a cash discount? Hmmmm???
As much as I would prefer to remove the CPS with a rounded out Torx and a butter knife in a driving snowstorm than take my car to a mechanic, when I am absolutely forced to do so, I let them know right off the bat that this is a matter of me needing their specific facilities or tools, not their ability to swing a wrench or guess what's wrong with my car.
It really is key that you set your expectations high with the mechanic or shop right off the bat. "I have X problem. I want an estimate to fix X problem. I will pay for the parts and labour required to fix X problem. If you put parts on to fix X problem, and it doesn't fix the problem, that's on you." If you've got a good working relationship with your mechanic, sure, pay for parts hung in error. If not...
While I was in Iraq, my wife had an O2 sensor crap out. She took it to a "reputable" mechanic. The mechanic replaced the O2 sensor, cleared the CEL, charged her over $300 and sent her on her way. The CEL lit back up within a block. She turned the car around and took it back. They kept it for two days before deciding it was the ECU, replaced that, charged her $800 and sent her on her way. Guess what happened when the CEL lit back up? She took it back and they spent two more days with it before deciding that they didn't know what was wrong with it. It took me, standing on the roof of my teamroom with a satellite telephone to explain to them that, in no instance, were we going to pay them a single penny for what they had done to "fix" the problem. I gave them the opportunity to provide my wife a rental car and valet service if they would like to collect her car and remove the ECU and O2 sensor they had replaced. Not surprisingly, they were not interested. So, I called my credit card company (USAA) and they stopped payment. There was some rankling about litigation but when I pointed out that I would call every one of their mechanics, sales reps, managers and the president of their company as witnesses, they relented. I don't feel great about the "free" ECU and O2 sensor we got. But, it is what it is.
Bottom line: the mechanic is supposed to provide you with a service; fixing your car. If they don't fix your car, why would you pay them? Sure, there's some guesswork involved but you're paying for their experience and professional opinion. If they guess incorrectly, the only impact that should have on you is that it takes longer to get the car done.