I'd genuinely say never. If it gets to the point that you're seriously considering cheating on your spouse (and unwilling/unable to work through what brought you there) you're better off pursuing a divorce.
If you feel it in you to cheat, then you sould be facing the problems within your marriage rather than looking externally for escapism. Don't do it. If that fails then the marriage is pointless or for the wrong reasons and should overtly be ended.