I went through this as a child so when my son started doing this, I had ideas of "do's" and "don'ts" in mind and my ideas created greater success for him than I had had.
First, we used "expectant praise" with our son, who was still doing this behavior in the second year of preschool. He would request a diaper to poop in, but use underwear at other times. We told him that he would eventually poop in the potty when the time was right for him. In short, we predicted his success on his own terms and took the shame and worry and pressure away.
Our sons stools were hard, likely due to holding poops in (I saw stool streaks in his underwear) so we also gave him mineral oil regularly (with juice or soda chasers) to soften the stools up first so he would be more likely to have success passing them comfortably on the potty. . Stool softening may be important to do first (check with a doctor ) because it can be hard to pass a hard stool, contributing to holding it in to avoid the pain of a hard stool. It becomes a vicious cycle too difficult for the child to resolve themselves. To tell a child to sit on the potty for "practice" under these conditions could make the whole pooping thing more traumatic and scary - it did for me, which is why I realized not to do this for my son.
We also told him that when he pooped in the potty, we would take him out to the toy store to get him a present (we tried to store prizes in the house but it became "pressure" so we stopped doing that.) Our child just turned 5, when this problem finally resolved in a matter of 3 poops in the potty, after the stool softening. We got him 3 prizes and after that, he did not need incentive. We also kept low key about his success because again, the point was it was on his terms. Jumping up and down about his pooping would have bothered him. He has not had problems since, in that area, but remains a control-oriented child who is quirky but happy and thriving in middle school. Part of his control issues come from being highly gifed, so I have found solutions to his ongoing, somewhat different, parenting needs in the gifted literature. It's not been only about the poop thing....this can just be the first sign of a child who needs more control than other children.
I hope this helps. I also know a middle schooler with continuing poop issues. My issues went on for years, which is why I strongly encourage parents to back off from control issues. My child has been spared that pattern.