MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / clean_state

Function clean_state

tests/conftest.py:64–100  ·  view source on GitHub ↗

Reset the app to a known-good ProjectFile state before each test. Same behaviour as the integration-suite fixture: disconnect any device, disable CSV export, create a fresh project, park in ProjectFile mode. Handles transient ConnectionErrors caused by rate limiting.

(api_client)

Source from the content-addressed store, hash-verified

62
63@pytest.fixture
64def clean_state(api_client):
65 """
66 Reset the app to a known-good ProjectFile state before each test.
67
68 Same behaviour as the integration-suite fixture: disconnect any device,
69 disable CSV export, create a fresh project, park in ProjectFile mode.
70 Handles transient ConnectionErrors caused by rate limiting.
71 """
72
73 def safe_command(func, *args, max_retries=2, **kwargs):
74 for attempt in range(max_retries):
75 try:
76 return func(*args, **kwargs)
77 except ConnectionError:
78 if attempt < max_retries - 1:
79 time.sleep(1.0)
80 try:
81 api_client.disconnect()
82 api_client.connect()
83 except Exception:
84 pass
85 except Exception:
86 pass
87
88 safe_command(api_client.disconnect_device)
89 safe_command(api_client.disable_csv_export)
90 safe_command(api_client.create_new_project)
91 safe_command(api_client.set_operation_mode, "project")
92
93 time.sleep(0.5)
94
95 yield
96
97 safe_command(api_client.disconnect_device)
98 safe_command(api_client.disable_csv_export)
99
100 time.sleep(0.5)
101
102
103# Tests that hammer many fresh connections with no pacing ("max stress" probes).

Callers

nothing calls this directly

Calls 1

safe_commandFunction · 0.70

Tested by

no test coverage detected