Best Python code snippet using sure_python
test_old_api.py
Source:test_old_api.py  
...643        ' context. It turns out that there are no actions providing ' \644        'that. Please double-check the implementation' % fullpath645    def with_setup(context):646        @action_for(context, depends_on=['something'])647        def lonely_action():648            pass649    @scenario(with_setup)650    def depends_on_fails(the):651        assert that(the.lonely_action).raises(AssertionError, error)652        return True653    assert depends_on_fails()654def test_depends_on_failing_due_not_calling_a_previous_action():655    "it fails when an action depends on some attribute that is being " \656        "provided by other actions"657    import os658    from sure import action_for, scenario659    fullpath = os.path.abspath(__file__).replace('.pyc', '.py')660    error = 'the action "my_action" defined at {0}:930 ' \661        'depends on the attribute "some_attr" to be available in the context.'\...helpmethods.py
Source:helpmethods.py  
1import sys2import bots3import time4def getLocalIP():5    """6    Method to retunr your local IP address7    Source:8    https://www.delftstack.com/howto/python/get-ip-address-python/#use-the-socket-gethostname-function-to-get-the-local-ip-address-in-python9    :return:10    """11    import socket12    return socket.gethostbyname(socket.gethostname())13"""14Gets socket message from host/client decodes it and prints it out15"""16def getSocketMsg(_socket, BUFSIZE):17    try:18        get_msg = _socket.recv(BUFSIZE)  # Receives msg from host/client19    except ConnectionResetError:20        sys.exit("Couldn't connect to socket")21    else:22        msg = get_msg.decode('utf-8')  # Decodes msg23        return msg24"""25Sends message to a connected sockets26"""27def sendSocketMsg(_socket, msg):28    time.sleep(1)29    try:30        send_msg = msg.encode('utf-8')  # Encodes msg31    except ConnectionResetError:32        sys.exit("Couldn't connect to socket")33    else:34        _socket.send(send_msg)  # Sends msg from host/client35def yes_no(Yes_or_no):36    if Yes_or_no == "Yes":37        return True38    return False39"""40- Takes in a name of a bot as a string an calls that bots,41- with 2 actions42- Validate that the input string for the name has a bot method with the same name43"""44def callBot(botName, ac1, ac2):45    bot_to_call = getattr(bots, botName)46    if ac2 == "None":47        ac2 = None48    _response = bot_to_call(ac1, ac2)49    return _response50def doesSysArg3Exist():51    """52    This function is used for client.py script to get name53    :return:54    """55    try:56        arg1 = sys.argv[3]57    except IndexError:58        print("No arguments")59    else:60        return arg161    return None62def isClientArgPosInt(clientNrArg):63    try:64        _clientNr = int(clientNrArg)65    except TypeError:66        print("Client number argument/input not an integer")67    else:68        if _clientNr < 0:69            print("Server only accepts numbers >= 0")70            return False71        else:72            return _clientNr73    return False74def isClientArgZero(isZero, thisFuncCalled):75    if isZero > 0:76        return False77    lonely_action = bots.__action__(1)78    lonely_suggestion = "Host: Would any of you want to {}?".format(lonely_action)79    print(lonely_suggestion)80    time.sleep(3)81    print("Any one there?")82    time.sleep(2)83    print("Wilson?")84    time.sleep(4)85    if thisFuncCalled >= 1:86        print("Did you really start a server for 0 clients again?...")87    else:88        print("Did you really start a server for 0 clients?...")89    time.sleep(2)90    print("This isn't fun, try asking for more than zero clients.")91    time.sleep(2)...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
