When a temptation comes our way, provided we don't consent to it or take any delight in it, we do not sin.
Yet, there are times when that temptation did not come out of nowhere.
In such cases we were one of the main causes of the temptation, as we put ourselves in a situation that led to that temptation.
Sinful temptations
St. Francis de Sales helps to clarify this spiritual reality in his Introduction to the Devout Life:
[I]t sometimes happens that temptation in itself is sin to us, because we have ourselves brought it upon us. For instance, if I know that gaming leads me to passion and blasphemy, and that all play is a temptation to me, I sin each and every time that I play, and I am responsible for all the temptations which may come upon me at the gaming table. So again, if I know that certain society involves me in temptation to evil, and yet I voluntarily seek it, I am unquestionably responsible for all that I may encounter in the way of temptation therein.
Determining whether a temptation was a sin requires discernment. A trusted spiritual advisor is often helpful in this regard, able to determine if you sought after the temptation, or if it simply popped into your mind.
St. Francis de Sales offers another point of advice in terms of discernment:
Therefore, when you are tempted to any sin, examine whether you voluntarily exposed yourself to the temptation, and if you find that you have done so by putting yourself into its way, or by not foreseeing the temptation, as you ought to have done, then it is sin; but if you have done nothing to bring about the temptation, it is not in anywise to be imputed to you as sin.
If someone is addicted to pornography, often simply logging onto the Internet when nobody is around is a recipe for disaster.
We need to be honest with ourselves and know which situations will bring about temptations.
It could even be a friend who gossips all the time. If we are trying to overcome our own attraction to gossip, it may mean spending less time with that friend. We know that if we are around them, we will be tempted and we won't be able to resist.
Leading a virtuous life, united to God, is not easy. The good news is that God can provide for us many graces that give us the strength to resist temptations when they come.