This function start the subprocess to start pgAdmin app
(self)
| 27 | self.app_config = app_config |
| 28 | |
| 29 | def start_app(self): |
| 30 | """ This function start the subprocess to start pgAdmin app """ |
| 31 | random_server_port = str(secrets.choice(range(10000, 65535))) |
| 32 | env = { |
| 33 | "PGADMIN_INT_PORT": random_server_port, |
| 34 | "SQLITE_PATH": str(self.app_config.TEST_SQLITE_PATH) |
| 35 | } |
| 36 | env.update(os.environ) |
| 37 | |
| 38 | # Add OS check for pass value for 'preexec_fn' |
| 39 | # Use sys.executable instead of bare "python" — macOS / many |
| 40 | # Linux distros do not provide a "python" alias, only "python3" |
| 41 | # or a venv-specific binary. sys.executable is the interpreter |
| 42 | # currently running the test runner, so the spawned pgAdmin |
| 43 | # uses the same Python and venv. |
| 44 | self.pgadmin_process = subprocess.Popen( |
| 45 | [sys.executable, "pgAdmin4.py"], |
| 46 | shell=False, |
| 47 | preexec_fn=None if os.name == 'nt' else os.setsid, |
| 48 | stderr=open(os.devnull, 'w'), |
| 49 | env=env |
| 50 | ) |
| 51 | |
| 52 | # Function is used to change the layout for feature test |
| 53 | test_utils.change_layout_for_feature_test() |
| 54 | |
| 55 | def launch_browser(retry_count): |
| 56 | try: |
| 57 | self.driver.get( |
| 58 | "http://" + self.app_config.DEFAULT_SERVER + ":" + |
| 59 | random_server_port |
| 60 | ) |
| 61 | |
| 62 | except WebDriverException: |
| 63 | # In case of WebDriverException sleep for 1 second and retry |
| 64 | # again. Retry 10 times and if still app will not start then |
| 65 | # raise exception. |
| 66 | time.sleep(1) |
| 67 | if retry_count < 60: |
| 68 | retry_count = retry_count + 1 |
| 69 | launch_browser(retry_count) |
| 70 | else: |
| 71 | raise RuntimeError('Unable to start python server even ' |
| 72 | 'after retrying 60 times.') |
| 73 | |
| 74 | if self.driver is not None: |
| 75 | launch_browser(0) |
| 76 | else: |
| 77 | return "http://" + self.app_config.DEFAULT_SERVER + ":" \ |
| 78 | + random_server_port |
| 79 | |
| 80 | def stop_app(self): |
| 81 | """ This function stop the started app by killing process """ |