I’d say it depends on the length of the dialogue. If we’re talking about 2-3 lines, then yeah, it should only be done on switching. If we’re talking about a speech that lasts several pages, I would think that it should be clear from context clues who is speaking.
Anyway, don’t get hung up on rules! Write how you want! Have a style!
Must be a day of the week that ends in y.