If the previous run needed to resolve a conflict, the branch will be left in a state where the rebase was not completed and thus on "no branch".
I think the safest thing to do would be to attempt to "git rebase --abort" before calling "checkout 5_BRANCH". This is because a previous test run could have failed to rebase, and you don't want it to affect subsequent tests.
Alternatively, we could finish the rebase, by, doing a "git add" of the change and then a "git rebase --continue", but this may be harder to get right. Also, it doesn't solve the problem where this can go wrong, leaving the workspace in an un-recoverable state.