The problem is that you are comparing actual result to expected result only partly. What if for range(2, 2000) the result are all primes, but the count is wrong, while for range(2, 3571) count is right, but there are non-primes? You should always test that actual result is identical to expected result.