Skip to content

Commit 6b26857

Browse files
authored
FIX: Optimizing test run time without impacting coverage (#380)
### Work Item / Issue Reference <!-- IMPORTANT: Please follow the PR template guidelines below. For mssql-python maintainers: Insert your ADO Work Item ID below (e.g. AB#37452) For external contributors: Insert Github Issue number below (e.g. #149) Only one reference is required - either GitHub issue OR ADO Work Item. --> <!-- mssql-python maintainers: ADO Work Item --> > [AB#41135](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/41135) <!-- External contributors: GitHub Issue --> > GitHub Issue: #<ISSUE_NUMBER> ------------------------------------------------------------------- ### Summary This pull request refactors and optimizes the `tests/test_013_SqlHandle_free_shutdown.py` test suite to improve test execution speed and maintainability. The main changes include reducing iteration counts and timeouts for faster test runs, and consolidating several similar tests into a single parameterized test using `pytest.mark.parametrize`. This makes the tests more efficient and easier to manage. Test performance improvements: * Reduced the number of iterations in connection churn and GC cycles, and lowered subprocess timeouts from 30 seconds to 5 seconds across multiple tests for much faster execution. [[1]](diffhunk://#diff-6e907f3a178ff11febfe8fc40f65fde6c89cd5aad910e5114558cec1e087ebd5L66-L71) [[2]](diffhunk://#diff-6e907f3a178ff11febfe8fc40f65fde6c89cd5aad910e5114558cec1e087ebd5L90-R90) [[3]](diffhunk://#diff-6e907f3a178ff11febfe8fc40f65fde6c89cd5aad910e5114558cec1e087ebd5L106-R106) [[4]](diffhunk://#diff-6e907f3a178ff11febfe8fc40f65fde6c89cd5aad910e5114558cec1e087ebd5L148-R148) [[5]](diffhunk://#diff-6e907f3a178ff11febfe8fc40f65fde6c89cd5aad910e5114558cec1e087ebd5L183-R183) [[6]](diffhunk://#diff-6e907f3a178ff11febfe8fc40f65fde6c89cd5aad910e5114558cec1e087ebd5L197-R199) [[7]](diffhunk://#diff-6e907f3a178ff11febfe8fc40f65fde6c89cd5aad910e5114558cec1e087ebd5L214-R214) [[8]](diffhunk://#diff-6e907f3a178ff11febfe8fc40f65fde6c89cd5aad910e5114558cec1e087ebd5L258-R258) [[9]](diffhunk://#diff-6e907f3a178ff11febfe8fc40f65fde6c89cd5aad910e5114558cec1e087ebd5L303-R303) [[10]](diffhunk://#diff-6e907f3a178ff11febfe8fc40f65fde6c89cd5aad910e5114558cec1e087ebd5L353-R353) [[11]](diffhunk://#diff-6e907f3a178ff11febfe8fc40f65fde6c89cd5aad910e5114558cec1e087ebd5L427-R427) [[12]](diffhunk://#diff-6e907f3a178ff11febfe8fc40f65fde6c89cd5aad910e5114558cec1e087ebd5L456-R456) [[13]](diffhunk://#diff-6e907f3a178ff11febfe8fc40f65fde6c89cd5aad910e5114558cec1e087ebd5L468-R468) [[14]](diffhunk://#diff-6e907f3a178ff11febfe8fc40f65fde6c89cd5aad910e5114558cec1e087ebd5L482-R486) [[15]](diffhunk://#diff-6e907f3a178ff11febfe8fc40f65fde6c89cd5aad910e5114558cec1e087ebd5L523-R523) [[16]](diffhunk://#diff-6e907f3a178ff11febfe8fc40f65fde6c89cd5aad910e5114558cec1e087ebd5L578-R578) [[17]](diffhunk://#diff-6e907f3a178ff11febfe8fc40f65fde6c89cd5aad910e5114558cec1e087ebd5L638-R638) [[18]](diffhunk://#diff-6e907f3a178ff11febfe8fc40f65fde6c89cd5aad910e5114558cec1e087ebd5L712-R712) Test suite maintainability: * Combined multiple similar tests for `_cleanup_connections()` into a single parameterized test using `pytest.mark.parametrize`, reducing code duplication and improving readability. The scenarios now covered are: normal flow, already closed connections, missing `_closed` attribute, exception handling, multiple connections, and WeakSet behavior. [[1]](diffhunk://#diff-6e907f3a178ff11febfe8fc40f65fde6c89cd5aad910e5114558cec1e087ebd5L724-L741) [[2]](diffhunk://#diff-6e907f3a178ff11febfe8fc40f65fde6c89cd5aad910e5114558cec1e087ebd5L761-L784) [[3]](diffhunk://#diff-6e907f3a178ff11febfe8fc40f65fde6c89cd5aad910e5114558cec1e087ebd5L801-L824) [[4]](diffhunk://#diff-6e907f3a178ff11febfe8fc40f65fde6c89cd5aad910e5114558cec1e087ebd5L836-L861) [[5]](diffhunk://#diff-6e907f3a178ff11febfe8fc40f65fde6c89cd5aad910e5114558cec1e087ebd5L889-L914) [[6]](diffhunk://#diff-6e907f3a178ff11febfe8fc40f65fde6c89cd5aad910e5114558cec1e087ebd5L938-L962) Test framework modernization: * Added `pytest` import and usage to support parameterized testing. Test output and assertion updates: * Updated test assertions and output strings to match the new, reduced iteration counts and to ensure test correctness after refactoring. [[1]](diffhunk://#diff-6e907f3a178ff11febfe8fc40f65fde6c89cd5aad910e5114558cec1e087ebd5L106-R106) [[2]](diffhunk://#diff-6e907f3a178ff11febfe8fc40f65fde6c89cd5aad910e5114558cec1e087ebd5L468-R468) [[3]](diffhunk://#diff-6e907f3a178ff11febfe8fc40f65fde6c89cd5aad910e5114558cec1e087ebd5L482-R486) These changes make the test suite faster, more robust, and easier to extend in the future.
1 parent a69c0ef commit 6b26857

File tree

3 files changed

+267
-556
lines changed

3 files changed

+267
-556
lines changed

tests/test_004_cursor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10370,7 +10370,7 @@ def test_procedures_result_set_info(cursor, db_connection):
1037010370
cursor.execute("EXEC pytest_proc_schema.test_no_results")
1037110371
# Procedures with no results should have no description and calling fetchall() should raise an error
1037210372
assert (
10373-
cursor.description is None,
10373+
cursor.description is None
1037410374
), "test_no_results should have no description (no result set)"
1037510375
# Don't call fetchall() on procedures with no results - this is invalid in ODBC
1037610376

0 commit comments

Comments
 (0)