Start the Quantinuum mock server and write a fake credentials file. Yields the path to the credentials file.
()
| 29 | |
| 30 | @pytest.fixture(scope="session") |
| 31 | def quantinuum_mock_server(): |
| 32 | """Start the Quantinuum mock server and write a fake credentials file. |
| 33 | |
| 34 | Yields the path to the credentials file. |
| 35 | """ |
| 36 | from network_utils import check_server_connection |
| 37 | try: |
| 38 | from utils.mock_qpu.quantinuum import startServer |
| 39 | except Exception: |
| 40 | pytest.skip("Mock qpu not available.", allow_module_level=False) |
| 41 | |
| 42 | with open(QUANTINUUM_CREDS_FILE, 'w') as f: |
| 43 | f.write('key: {}\nrefresh: {}\ntime: 0'.format("nexus_key", |
| 44 | "nexus_refresh")) |
| 45 | |
| 46 | cudaq.set_random_seed(13) |
| 47 | |
| 48 | p = Process(target=startServer, args=(QUANTINUUM_MOCK_PORT,)) |
| 49 | p.start() |
| 50 | |
| 51 | if not check_server_connection(QUANTINUUM_MOCK_PORT): |
| 52 | p.terminate() |
| 53 | pytest.exit("Mock server did not start in time, skipping tests.", |
| 54 | returncode=1) |
| 55 | |
| 56 | yield QUANTINUUM_CREDS_FILE |
| 57 | |
| 58 | p.terminate() |
| 59 | try: |
| 60 | os.remove(QUANTINUUM_CREDS_FILE) |
| 61 | except FileNotFoundError: |
| 62 | pass |
| 63 | |
| 64 | |
| 65 | # --------------------------------------------------------------------------- |
nothing calls this directly
no test coverage detected