How soon before period can I test

Ka
How soon before my period comes can I take a pregnancy test for it to be accurate?