Yes, loss.backward() using the test data would compute the gradients in the same way as during training.
optimizer.step() would then update all parameters with their gradients, which would create a data leakage, since you would be training on the test dataset.