'How to stop execution test if 2 or more tests failed?

Hello i have so issue when i try to stop test if 2 or more test failed, I'm using listener lib for this, I'm checking status, and when status "FAIL" add to the counter, when counter == 2, tests must stop, but it doesn't.

from robot.libraries.BuiltIn import BuiltIn

class PythonListener(object):
    ROBOT_LIBRARY_SCOPE = 'TEST SUITE'
    ROBOT_LISTENER_API_VERSION = 2

def __init__(self):
    self.ROBOT_LIBRARY_LISTENER = self

def end_test(self, name, attrs):
    global result
    global count
    count = 0
    result = None
    print 'Suite %s (%s) start %s.' % (name, attrs['longname'], attrs['status'])
    if attrs['status'] == "FAIL":
        count += 1
        if count >= 2:
            result = BuiltIn.fatal_error(self)
            return result


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source