@William-Hsu in automated testing we try not to use logic like this because we want to be able to repeat the test case in identical steps every time. Without that it makes it difficult to understand if it fails how the failure occurred because we wouldn't know whether it the code has gone through this `if` statement or not.
I noticed that checking this checkbox sets the `keyboards.layouts.spanish` setting to True. If you set this setting to False in the setUp of this test then you can remove this if statement. Thus we start the test from a known start point every time.