Skip to content

Commit 7831a6e

Browse files
Address code quality
1 parent 97005e8 commit 7831a6e

5 files changed

Lines changed: 14 additions & 8 deletions

File tree

.github/copilot-instructions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ In case of any conflicting instructions, the following hierarchy shall apply. If
4646
- Consider non-native English speakers in code comments and documentation, using clear and simple language.
4747
- Treat accessibility as a default quality requirement across the entire repository, not only for presentations.
4848
- New or updated user-facing experiences (docs, webpages, notebooks, dashboards/workbooks, and slide content) must target WCAG 2.0 AA contrast and non-color-only communication as the baseline.
49+
- Continuously refine repository instructions, skills, and agents when a surfaced problem reveals an addressable gap. Update the narrowest authoritative customization in the same change when practical, so future work benefits without duplicating or overfitting guidance.
4950

5051
## Consistency & Uniformity
5152

.github/python.instructions.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ Before completing any Python code changes, verify:
101101
- Slow tests (> 0.1s runtime) should be identified and fixed, if possible.
102102
- Add or update pytest unit tests when changing behavior.
103103
- Prefer focused tests for the code being changed.
104+
- When testing cleanup after an exception, place `pytest.raises(...)` in an outer `with` block and the resource-owning context manager in a nested inner block. Do not combine them in one comma-separated `with` statement because static analysis may report the cleanup assertions as unreachable.
105+
- If static analysis still treats assertions after `pytest.raises(...)` as unreachable because the test body contains a literal `raise`, trigger the expected exception through the exercised method or a mock `side_effect` instead. Keep the exception and post-block cleanup assertions unchanged.
104106
- Avoid tests that require live Azure access; mock Azure CLI interactions and `azure_resources` helpers.
105107
- Every extracted helper requires focused tests for its public success and failure contracts. Include malformed inputs and resource cleanup where applicable.
106108
- Place sample-local helper tests in `tests/python/test_<sample>_helpers.py` and target at least 95% meaningful statement and branch coverage for changed helper modules.

tests/python/test_auth_testing.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,9 @@ def test_structured_expectation_rejects_non_json_response(requests_mock, tests_m
109109

110110
@pytest.mark.unit
111111
def test_context_manager_closes_requests_on_exception(requests_mock, tests_mock):
112-
with pytest.raises(RuntimeError), RoleBasedAuthTestRunner(requests_mock, tests_mock, 'jwt-key'):
113-
raise RuntimeError('test failure')
112+
with pytest.raises(RuntimeError):
113+
with RoleBasedAuthTestRunner(requests_mock, tests_mock, 'jwt-key'):
114+
raise RuntimeError('test failure')
114115

115116
requests_mock.close.assert_called_once_with()
116117

tests/python/test_dynamic_cors_helpers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,12 @@ def test_runner_persists_results_when_cell_raises(monkeypatch, tmp_path):
7070
runner = _create_runner(monkeypatch, results_path)
7171
suite = MagicMock()
7272
suite.verify.return_value = False
73+
fail_cell = MagicMock(side_effect=RuntimeError('cell failed'))
7374

7475
with pytest.raises(RuntimeError, match='cell failed'):
7576
with runner:
7677
runner.track(suite, 'Option 1', 'recorded before failure', 500, 200)
77-
raise RuntimeError('cell failed')
78+
fail_cell()
7879

7980
assert load_test_results(results_path)[0]['Test'] == 'recorded before failure'
8081
runner.session.close.assert_called_once()

tests/python/test_secure_blob_access_helpers.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,12 @@ def test_runner_preserves_failed_download_body_and_closes_after_exception():
142142
session.get.return_value.text = 'forbidden details'
143143
runner = SecureBlobAccessRunner(requests, session_factory=lambda: session)
144144

145-
with pytest.raises(RuntimeError, match='cell failed'), runner:
146-
download = runner.download(ValetKey('https://storage/blob', None))
147-
assert download.content is None
148-
assert download.response_body == 'forbidden details'
149-
raise RuntimeError('cell failed')
145+
with pytest.raises(RuntimeError, match='cell failed'):
146+
with runner:
147+
download = runner.download(ValetKey('https://storage/blob', None))
148+
assert download.content is None
149+
assert download.response_body == 'forbidden details'
150+
raise RuntimeError('cell failed')
150151

151152
session.close.assert_called_once_with()
152153
requests.close.assert_called_once_with()

0 commit comments

Comments
 (0)