A KENYAN appeals court has finally outlawed the use of forced anal exams to test for whether two men had sex.

Medical practitioners were able to conduct these tests — without warning — on anyone suspected of homosexual activity in the East African nation, where gay sex is punishable with up to 14 years in prison.

Gay rights advocates have cheered the decision, saying forced anal exams amount to torture.

“The ruling is a tremendous step not only in upholding the dignity of homosexuals who had been subjected to the indignities of anal examinations but also to the rule of law in Kenya,” said Eric Gitari, the executive director of the National Gay and Lesbian Human Rights Commission.

According to Human Rights Watch, these examinations often involve doctors inserting their fingers or other objects into the anus of the accused.

They claim they can draw conclusions from the shape and tone of the interior to determine whether the person has engaged in anal sex, despite current scientific opinion holding that it’s impossible to determine whether a person has engaged in same-sex conduct from doing so.

The barbaric “medical” practice has taken place on men suspected of having gay sex since 2010, and also occurs in Cameroon, Egypt, Lebanon, Tunisia, Turkmenistan, Uganda and Zambia.

‘Forced anal examinations are a form of cruel, degrading, and inhuman treatment that can rise to the level of torture,” the organisation said.

Several victims said they see it as a form of sexual violence.

In 2016, a Tunisian victim told the organisation: “I felt like I was an animal. I felt I wasn’t human. ... When I got dressed they put handcuffs on me and I went out, feeling completely in shock. I couldn’t absorb what was going on.

“The two police were standing and watching what the doctor was doing. I felt violated. I didn’t want to be naked in front of people — not just one person, but three people … It was the first time anything like this had happened to me and I couldn’t absorb anything.”

Another victim, who was imprisoned following a doctor’s “verdict”, said it was one of the “worst times in (his) life”.

The lesbian, gay, bisexual and transgender communities in the East African nation have complained of harassment, which in some cases is violent.

Gay people often are ostracised by families and their communities and are discriminated against when it comes to renting property and finding jobs.