That is a really tough question.
I wonder if it helps to step back from it and ask two prior questions:
What does it look like to love God? What does it look like to love my neighbor?
In terms of the first question, we must be loyal to God, whatever the consequences.
However, God is asking us to love our neighbors. What does it look like to show love for your teachers?
Let’s take a worst-case scenario: a teacher who wants to deconvert you and is hostile to your faith.
Even in that situation, you have options.
For instance, as @dennis recommended, you can demonstrate excellence by showing the teacher that you fully understand the material as expected. Referring to the textbooks, lectures, and class discussion is a wise way to fulfill the assignment without expressing it as your own thoughts.
In addition, by treating the teacher with respect and elevating the classroom culture, you can make his or her job easier. It’s so hard to fight with someone who refuses to fight back! If your only response to their challenges is a genuinely kind and thoughtful answer, the contrast will be clear to everyone.
I think it’s then, once you have credibility because of your studies, and relational equity, because of how you treat people, that there’s more of an opportunity to share your own convictions. For instance, in addition to submitting the required paper, you can also provide an appendix with your own reflections on the topic. Or after answering the question on the test, you can also share another sentence or a paragraph with your own evaluation of what was taught.
Sometimes, I wanted to be “persecuted” because it felt good to “suffer for Jesus.” But in most cases, I was suffering for being obnoxious or unprepared. By asking myself how God could help me rise to a higher standard of love for others, I experienced new opportunities to share my faith in relationships where trust had been built.
From your posts, I don’t think that’s your issue, but I share what I’ve learned in case it is helpful as you discern your path forward. I think there are potentially many more options available to you than it might seem like you have right now. Perhaps ask God and others for creative ways to maintain your convictions in a way that builds trust.