Ensure Serial Studio is in a clean state. Disconnects device, disables exports, creates a new project, and parks the app in ProjectFile mode. ProjectFile is the right default because most integration tests exercise project-editor mutations, CSV export, workspaces, datasets, etc
(api_client)
| 72 | |
| 73 | @pytest.fixture |
| 74 | def clean_state(api_client): |
| 75 | """ |
| 76 | Ensure Serial Studio is in a clean state. |
| 77 | |
| 78 | Disconnects device, disables exports, creates a new project, and parks |
| 79 | the app in ProjectFile mode. ProjectFile is the right default because |
| 80 | most integration tests exercise project-editor mutations, CSV export, |
| 81 | workspaces, datasets, etc. — all of which are gated off in ConsoleOnly |
| 82 | (the dumb-terminal mode that replaced the old "Device Sends JSON" slot |
| 83 | in v3.3). Tests that need QuickPlot or ConsoleOnly explicitly set their |
| 84 | own mode after this fixture runs. |
| 85 | |
| 86 | Handles server disconnections gracefully (e.g., from rate limiting). |
| 87 | """ |
| 88 | |
| 89 | # Helper to retry operations if server disconnected |
| 90 | def safe_command(func, *args, max_retries=2, **kwargs): |
| 91 | for attempt in range(max_retries): |
| 92 | try: |
| 93 | return func(*args, **kwargs) |
| 94 | except ConnectionError: |
| 95 | if attempt < max_retries - 1: |
| 96 | # Server might have disconnected us, try to reconnect |
| 97 | time.sleep(1.0) |
| 98 | try: |
| 99 | api_client.disconnect() |
| 100 | api_client.connect() |
| 101 | except: |
| 102 | pass |
| 103 | else: |
| 104 | # Final attempt failed, ignore |
| 105 | pass |
| 106 | except Exception: |
| 107 | pass |
| 108 | |
| 109 | # Clean up before test |
| 110 | safe_command(api_client.disconnect_device) |
| 111 | safe_command(api_client.disable_csv_export) |
| 112 | safe_command(api_client.create_new_project) |
| 113 | safe_command(api_client.set_operation_mode, "project") |
| 114 | |
| 115 | # Add delay to let server recover from any rate limiting |
| 116 | time.sleep(0.5) |
| 117 | |
| 118 | yield |
| 119 | |
| 120 | # Clean up after test |
| 121 | safe_command(api_client.disconnect_device) |
| 122 | safe_command(api_client.disable_csv_export) |
| 123 | |
| 124 | # Add delay before next test |
| 125 | time.sleep(0.5) |
| 126 | |
| 127 | |
| 128 | @pytest.fixture |
nothing calls this directly
no test coverage detected