why does G-d test us sometimes and yet in our prayers we ask for G-d not to give us any tests because we are capable of failing it and why do we ask for G-d not to test us if G-d knows what’s best for us?
This is similar to the basic question of why do we pray at all for anything: Surely G-d knows what is best for us, so what’s the point of prayer for health, for income, for wisdom, and for anything else?
Many approaches have been written concerning this basic question. One basic approach is that it is our duty to pray to Hashem, and therefore to make our needs and our desires into a relationship with Him.
The prayer itself states that we have a close relationship with Hashem, and that He is the one who caters for our needs and desires. Sometimes He decides that this is not best for us; either way, the prayer is essential in expressing the relationship itself, and our dependence on Hashem.
When we pray that Hashem should not bring us to trials, we make the subject of trials into a relationship with Hashem. We also know that we will have trials. Our entire life is full of trials. However, we pray to Hashem that we will not come to trials that are liable to bring us to sin.