It's probably that you want to be perfect at everything you do. Unlike other answers may tell you, you don't need medication at all. My entire family suffers from it (I have lost sleep, and before I do something I am nervous about, I always get stomach aches or really tense muscles).
All you have to think about is, if something does not work out, what is the absolute worst that can happen? If you think about it, the crazy things you worry will happen have a very small chance of occurring. But, if you think it's likely that something bad WILL happen, then take steps to prevent it the best you can. That way, if it still does not work out, you can confidently say to yourself, "well, I gave it my best shot."
For example, if you lose sleep over the test next week, think about what you can do to avoid failing it, and do it. Most clear solution there will be to study. Don't lose sleep. Just think of the worst and what are the chances of it happening, or whether you're willing to accept it.