How to use pytest fixtures teardown when we have a function which is called multiple times in a code?

  fixtures, pytest, python, teardown

we have function called delete_product in assert which is called multiple times, how to remove all instances of delete_product and write one single function using pytest fixtures, code is below

try:
        output = subprocess.check_output(cmd, shell=True).decode()
    except subprocess.CalledProcessError as error:
        logger.error("error: {}".format(error))
        assert delete_product(role, product_name), 'Product ' + product_name + ' could not be deleted by role ' + role
        assert False, error
    try:
        assert "assumed-role/" + storagerole + "/kiam-kiam" in output, 'Expected role ' + storagerole + ' was not assumed within container'
    except AssertionError as error:
        logger.error("error: {}".format(error))
        assert delete_product(role, product_name), 'Product ' + product_name + ' could not be deleted by role ' + role
        assert False, error

    logger.info("All steps passed, deleting pod: {}".format(launched_pod))
    assert delete_product(role, product_name), 'Product ' + product_name + ' could not be deleted by role ' + role

Source: Python Questions

LEAVE A COMMENT