Do I have to take a pregnancy test when my period is about to come or maybe a week before my period?

When period is due. Urine pregnancy test measure presence of a hormone called human Chorionic Gonadotropin (hcg). This hormone is produced by the placenta shortly after the embryo attaches to the uterine lining and builds up rapidly in your body in the first few days of pregnancy. This typically occurs 2 weeks after conception so it is recommended that you wait until at least one day after you miss your period.
After is >reliable. I do not know whether or not you are trying to achieve pregnancy . Usually pregnancy test is done when you suspect pregnancy because you missed your period unless you know how to recognize your ovulation or most fertile days in your cycle an you try to be pregnant then you can test even before the day that you were expecting your period (suppose to come 9-16 days after peak or ovulation).