Best Python code snippet using avocado_python
runner.py
Source:runner.py
...23from avocado.core.utils import messages24class RobotRunner(BaseRunner):25 name = "robot"26 description = "Runner for Robot Framework tests"27 def _uri_to_file_suite_test(self):28 """Converts the uri to a file name, suit name and test name"""29 if not self.runnable.uri:30 return (None, None, None)31 file_name_suite_test = self.runnable.uri.split(":", 1)32 if len(file_name_suite_test) == 1:33 return (file_name_suite_test[0], None, None)34 file_name, suite_test = file_name_suite_test35 suite_name_test_name = suite_test.split(".", 1)36 if len(suite_name_test_name) == 1:37 return (file_name, suite_test, None)38 suite_name, test_name = suite_name_test_name39 return (file_name, suite_name, test_name)40 def _run(self, file_name, suite_name, test_name, queue):41 stdout = io.StringIO()42 stderr = io.StringIO()43 output_dir = tempfile.mkdtemp(prefix=".avocado-robot")44 native_robot_result = run(45 file_name,46 suite=suite_name,47 test=test_name,48 outputdir=output_dir,49 stdout=stdout,50 stderr=stderr,51 )52 if native_robot_result:53 result = "fail"54 else:55 result = "pass"56 stdout.seek(0)57 stderr.seek(0)58 output = self.prepare_status(59 "finished",60 {61 "result": result,62 "stdout": stdout.read().encode(),63 "stderr": stderr.read().encode(),64 },65 )66 stdout.close()67 stderr.close()68 queue.put(output)69 def run(self, runnable):70 # pylint: disable=W020171 self.runnable = runnable72 file_name, suite_name, test_name = self._uri_to_file_suite_test()73 if not all([file_name, suite_name, test_name]):74 yield messages.FinishedMessage.get("error", fail_reason="Invalid URI given")75 return76 queue = multiprocessing.SimpleQueue()77 process = multiprocessing.Process(78 target=self._run, args=(file_name, suite_name, test_name, queue)79 )80 process.start()81 yield messages.StartedMessage.get()82 yield from self.running_loop(lambda: not queue.empty())83 status = queue.get()84 yield messages.StdoutMessage.get(status["stdout"])85 yield messages.StderrMessage.get(status["stderr"])86 yield messages.FinishedMessage.get(status["result"])...
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!!