Arusha, Tanzania — It happens twice a year at Arusha Secondary School. Each one of the school's 800 female students is accompanied into a toilet and told to pee in a jar. Outside the cubicle, a teacher waits to make sure the samples are not swapped.

The girls are taking compulsory pregnancy tests. And if they come back positive, the student is expelled immediately.

The tests have been happening at this school, for students from grades eight and up, for three years.

CNN visited two other schools in the Kilimanjaro and Arusha regions where similar testing took place; three more schools confirmed the tests in phone interviews.

Elifuraha, who CNN is referring to by her first name, finds it difficult to talk about the shame she felt when teachers at the Moshono Secondary School in Arusha, summoned her for a mandatory pregnancy test.

Elifuraha was 16 years old when she got pregnant. She tried to conceal her morning sickness at school, blaming it on malaria.

"All the students were called in a room and the female teachers started to inspect us... they were touching our stomachs," the 19-year-old mother told CNN, as a tear rolled down her cheek.

She knew she was pregnant, but was trying hard to hide her growing stomach. After admitting her pregnancy, she was immediately expelled.

Tanzania uses a morality clause in a 2002 education law to give schools the legal framework needed to expel students -- the practice originally dates back to the 1960s. The law has been more widely applied since President John Pombe Magufuli took office in 2015.

Last June, Magufuli, dubbed "The Bulldozer," went a step further, announcing that pregnant students would not be allowed to return to school after giving birth.

"In my administration as the President no pregnant girl will go back to school... she has chosen that of kind life, let her take care of the child," he said at a public rally in 2017. His speech removed any discretion schools had over how they enforced the morality rule.

There are no official statistics on how many pregnant girls have been expelled from Tanzanian schools. The US-based Center for Reproductive Rights, an international advocacy group, estimated in 2013 that over 8,000 pregnant girls were being expelled or dropped out from Tanzanian schools every year.

The Presidential decree last year goes directly against the previous government's efforts to introduce a school re-entry policy for teenage mothers.

Anna Ulimboka, a nurse who oversees the pregnancy testing in Arusha Secondary School, says the tests are a good thing. And many of her students agree.

Several girls told CNN they believe the tests are in place to protect them and they view them as a normal part of their school experience.

Students attend class at Arusha Secondary School.

"Before we started testing them, so many girls used to get pregnant, while they were in school, but after seeing that they were being tested before and after going for their holidays, it makes them avoid relationships with boys," Ulimboka said.

CNN visited the school accompanied by officials from Tanzania's Ministry of Health, and the regional government office. Speaking in the presence of the officials, Ulimboka said the tests and the policy of expelling pregnant students were necessary.

"(A pregnant girl) is a bad example to other students," she said. "The others will learn that even if we mess up, we shall be allowed back to school."

Girls gather between lessons at Arusha Secondary School. At least once a semester, after coming back from holidays, the girls are rounded up in the dining hall for a mandatory pregnancy test.

However, Ulimboka said she felt bad for girls who had been expelled.

"I always advise them that even if they get pregnant that's not the end, and that they should not give up."

Shilinde Ngalula, a lawyer with Legal and Human Rights Centre in Tanzania, said forcing pregnant girls out of school violates Tanzania's constitution, which includes the right to education.

"Because of the order of the President, you expel them...you are punishing them without even considering how she got pregnant," he said.

"There are many instances of rape...a girl might find herself pregnant because of rape, because of assault or forced marriages, it is not her fault."

NGOs have been forced to abandon campaigning on the issue with the Legal and Human Rights Centre one of the last in Tanzania still speaking out against Magufuli's platform.

Young women dressed in uniform walk their children to daycare before attending trades courses at the Faraja Center, a shelter for vulnerable women.

In July 2017, opposition MP Halima Mdee was arrested for denouncing the President for the ban on pregnant schoolgirls, which she also claims is contrary to the constitution. Her case was highlighted by the US State Department's report into human rights in Tanzania as one of the examples of a crackdown on Magufuli's critics.

"If you speak against the government order, and especially against the order of the president, you are in trouble...it is really easy for an NGO to be deregistered, it's a threat," Ngalula said.

Alongside Tanzania, Equatorial Guinea and Sierra Leone also deny pregnant girls and adolescent mothers the right to study in public schools, which advocates say goes against the human rights treaties that all three countries have signed.

"It squarely falls within the definition of a violation of not just the right to education but also other rights of girls," said Elin Martinez, children's rights expert at Human Rights Watch.

Elifuraha's son watches, pencil in hand, as she flips through her notes from a tailoring class at the Faraja Center.

All three countries have repeatedly found themselves under international pressure to repeal the policy. The United Nations High Commissioner for Human Rights and other international organizations appealed to the Tanzanian government to change the rules.

Several human rights organizations have also recently launched a court case against Sierra Leone over its policy.

CNN has reached out to the Tanzanian government for comment, but has not yet received reply. The governments of Sierra Leone and Equatorial Guinea have also not responded to requests for comment.

In Tanzania, while pregnancy testing remains a regular part of school life, Magufuli's administration has also launched a crackdown on family planning.

At a public rally in September, the President urged women to stop using contraception to increase Tanzania's population and called those using birth control "lazy."

A few weeks later, the government ordered the suspension of family planning advertisements on TV and radio stations in the country.

Because standalone sex education is not on the national curriculum in Tanzania, many girls don't learn that having sex can lead to becoming pregnant.

Eighteen-year-old Lilian was one of them. She got pregnant when she was 16.

Lilian holds her daughter Favor at the Faraja Center. Lilian is learning tailoring and hair braiding in the hopes of getting a job when she leaves the shelter.

"There are [some women] who get to be educated and understand that sex before marriage has consequences...yet others don't have a clue. In my case I had no knowledge and that is why I got pregnant."

Around a quarter of Tanzanian girls aged between 15 and 19 are mothers or pregnant. Child marriage is still prevalent in the country -- 37% of women aged 20 to 24 having been married before they turned 18, according to official data from 2010, the latest available. More than a quarter of girls married before the age of 19 have husbands who are 10 or more years older, according to the same survey.

The ban on pregnant students is one of the ways Magufuli wants to tackle the teenage pregnancy problem.

Magufuli says that pregnant girls and young mothers would set a bad example for other pupils.

Boys and men who impregnate school girls face prison sentences of up to 30 years. Local media and NGOs have reported arrests of pregnant girls who were not willing to disclose the identity of the men who impregnated them.

In Ghona School near Moshi in the north-east of the country, students are reminded of the harsh realities every day.

Calendars depicting a crying pregnant girl in a school uniform can be found in almost every classroom. In the scene, the girl is being turned away from school, her parents, her community and the government.

School calendars warn against the consequences of pregnancy, and trading sex for rides with "boda boda" (motorcycle taxi) drivers.

Lilian was already expecting her baby when President Magufuli made his landmark speech on expelling pregnant students.

She liked studying chemistry, biology and geography and knowing she wouldn't be allowed back into school was devastating.

"I wanted to achieve my goals, but I was forced to cut them short, stay at home and wait for another opportunity," she said.

Lilian and her daughter Favor now live at the Faraja Center , a shelter for vulnerable women and young mothers, many of whom have been kicked out of school as a result of their pregnancy.

Like the rest of the shelter's residents, Lilian is learning tailoring and hair braiding. It's a far cry from studying science, but it will help her get a job after she leaves the shelter.

Lilian sits on the edge of her bed after getting her daughter Favor ready for the day.

And she hasn't completely given up on her dreams just yet. She has kept her physics notebook, wrapped in plain brown paper. She is hoping she will, one day, be allowed to return to school and retake the class.

No public school is allowed to re-admit Lilian and tuition at the few private schools that could still accept her cost around $800 a year. Her only option is to find a sponsor, or get a place in one of the handful of NGO-funded schools in the country.

Like Lilian, Elifuraha also had big plans that she put aside when she became pregnant.

Elifuraha dreamed of joining the Tanzanian army, but didn't complete enough schooling to meet the requirements before she was expelled.

"If things were not the way they are, I would love to go back to school," she said.