(self, args, writer)
| 517 | |
| 518 | @contextmanager |
| 519 | def run_process(self, args, writer): |
| 520 | process = self.create_process(args, writer) |
| 521 | writer.process = process |
| 522 | stdout = [] |
| 523 | stderr = [] |
| 524 | finish = [False] |
| 525 | dct_with_stdout_stder = {} |
| 526 | fail_with_message = False |
| 527 | |
| 528 | try: |
| 529 | start_in_daemon_thread(read_process, (process.stdout, stdout, sys.stdout, "stdout", finish)) |
| 530 | start_in_daemon_thread(read_process, (process.stderr, stderr, sys.stderr, "stderr", finish)) |
| 531 | |
| 532 | if SHOW_OTHER_DEBUG_INFO: |
| 533 | print("Both processes started") |
| 534 | |
| 535 | # polls can fail (because the process may finish and the thread still not -- so, we give it some more chances to |
| 536 | # finish successfully). |
| 537 | initial_time = time.time() |
| 538 | shown_intermediate = False |
| 539 | dumped_threads = False |
| 540 | |
| 541 | dct_with_stdout_stder["stdout"] = stdout |
| 542 | dct_with_stdout_stder["stderr"] = stderr |
| 543 | try: |
| 544 | yield dct_with_stdout_stder |
| 545 | except: |
| 546 | fail_with_message = True |
| 547 | # Let's print the actuayl exception here (it doesn't appear properly on Python 2 and |
| 548 | # on Python 3 it's hard to find because pytest output is too verbose). |
| 549 | sys.stderr.write("***********\n") |
| 550 | sys.stderr.write("***********\n") |
| 551 | sys.stderr.write("***********\n") |
| 552 | traceback.print_exc() |
| 553 | sys.stderr.write("***********\n") |
| 554 | sys.stderr.write("***********\n") |
| 555 | sys.stderr.write("***********\n") |
| 556 | raise |
| 557 | |
| 558 | if not writer.finished_ok: |
| 559 | self.fail_with_message( |
| 560 | "The thread that was doing the tests didn't finish successfully (writer.finished_ok = True not set).", |
| 561 | stdout, |
| 562 | stderr, |
| 563 | writer, |
| 564 | ) |
| 565 | |
| 566 | while True: |
| 567 | if process.poll() is not None: |
| 568 | if writer.EXPECTED_RETURNCODE != "any": |
| 569 | expected_returncode = writer.EXPECTED_RETURNCODE |
| 570 | if not isinstance(expected_returncode, (list, tuple)): |
| 571 | expected_returncode = (expected_returncode,) |
| 572 | |
| 573 | if process.returncode not in expected_returncode: |
| 574 | self.fail_with_message( |
| 575 | "Expected process.returncode to be %s. Found: %s" % (writer.EXPECTED_RETURNCODE, process.returncode), |
| 576 | stdout, |
no test coverage detected