I am using ThreadPoolExecutor to run two tests simultaneously in python, for some tests, however I have a problem, and that is that let's say there is a main test and a secondary test, both will be executed from the beginning, however the secondary test will finish first, I return the result, to later use it as a parameter in the main test, since by the time I require it I have already finished the secondary test, but I don't see how to apply that.
I am using Selenium to do the test, and from my main.py file I send it to call the methods, so I have my code.
from concurrent.futures import ThreadPoolExecutor
def PruebaPrincipal(opcion_sistema, opcion_ambiente, opcion_usuario, opcion_especifica, tipo_de_credito, resultado_folio):
resultado_folio = resultado_folio_future.result()
with Flujos_obligatorios_originacion() as bot1:
limpiar_pantalla()
bot1.get_url(opcion_sistema, opcion_ambiente)
bot1.iniciar_sesion(opcion_ambiente, opcion_usuario)
bot1.Crear_Solicitud(tipo_de_credito)
resultado_database = bot1.Establecer_base_de_datos(opcion_ambiente)
curp_cliente = bot1.Llenar_Formulario_Solicitud(opcion_sistema, opcion_especifica, resultado_database, opcion_ambiente)
bot1.Solicitud_Tipo_de_Credito(tipo_de_credito)
bot1.Solicitud_Datos_del_Credito(resultado_folio, resultado_database, curp_cliente, tipo_de_credito)
bot1.cerrar_sesion()
bot1.close()
def PruebaSecundaria(opcion_ambiente, opcion_sistema):
with Flujos_obligatorios_originacion() as bot2:
resultado_folio_future = bot2.Obtener_Folio_Nav(opcion_ambiente, opcion_sistema)
return resultado_folio_future
with ThreadPoolExecutor(max_workers=2) as executor:
resultado_folio_future = executor.submit(PruebaSecundaria, opcion_ambiente, opcion_sistema)
executor.submit(PruebaPrincipal, opcion_sistema, opcion_ambiente, opcion_usuario, opcion_especifica, tipo_de_credito, resultado_folio_future)
I hope that the secondary test obtains a value for me to use in the main test, sending it as a parameter.
Sure. You get a
Futurefromexecutor.submit(); calling.result()on a future waits for the future to have completed and returns the value (or raises an exception if the future failed).This prints out