You're an M3, not an M4, right?
If you're an M4...July is far too late and you need to take it within the next month or two at all costs.
If you're an M3 - depends on what you're applying to and your academic record, but July is almost certainly fine. If you have significant red flags to not pass board exams, e.g. previous course/Step failures, I'd take it as early as possible. So you can hopefully have a passing score in time to submit your application to residency programs and alleviate any concerns there, and time to retake it on the off chance you fail. If you have done at least average on all your courses and boards so far, you can probably just take it based on your preference and specialty. Some specialties just want you to have a passing score by the time you start residency, so you could take it in the spring if you wanted to, while others require you to have a passing CS score in order to rank you, in which case you'd want to do it in the summer/fall.