If you put Webots in Realtime mode before running a test using the WebotsSimulator class, it runs the test in Fast mode.
One option would be to have WebotsSimulator get the mode from the controller before loading the world and restore it after the world is loaded.
Another option would be for the controller to store the mode to a file while loading the world.