I am trying to limit the CPU usage of one python script using
ulimit -v 400000; ulimit -t 30; python test.py
ulimit -t sets the CPU time limit. While your program is sleeping it doesn't use any CPU time, so that time doesn't count. It will only occupy a few CPU cycles to go to sleep again, that's why it's not killed.
You can't specify a real time limit using ulimit.