Though you can get divorced whenever you want, it often makes sense to wait until a divorce is completed before filing for bankruptcy. Issues regarding property ownership and responsibilities for personal debt will often be cleared up in the divorce.
If you decide to file for divorce in the midst of a chapter 7 case, the filing will likely have little impact: The chapter 7 case will likely end months before the divorce is finalized. If you are on the cusp of filing a chapter 13 case with your spouse and divorce is looming on the horizon, wait to file the divorce until you have spoken to your attorney. You cannot file together if you are no longer married and if you have already filed bankruptcy, at least one of you will likely need to find another bankruptcy attorney to handle your case.