Refactor test suite to use parametrized tests and reduce duplication#98
Conversation
Consolidate orders_get/positions_get, *_as_dicts skip_to_datetime, and index_keys coverage in test_dataframe.py into pytest.mark.parametrize cases with stable IDs, drop the symbols_total test now redundant with test_total_methods, and parametrize the equivalent orders_get/positions_get pair in test_mt5.py plus the small decorator branch cases in test_utils.py.
Merge symbol_info_as_dict/symbol_info_tick_as_dict skip_to_datetime coverage into one parametrized test, and split symbols_get_as_df_with_params into isolated skip_to_datetime and index_keys cases.
Add explicit skip/convert parametrize axes to test_get_as_dicts_skip_to_datetime, test_symbol_info_dict_methods_with_skip_to_datetime, test_copy_rates_as_dicts, and test_copy_ticks_as_dicts so a failure in either mode is isolated. Also parametrize test_decorator_with_skip_toggle in test_utils.py and test_version_methods_raise_mt5_runtime_error_on_none_response by client_method.
Merge test_history_orders_get_filters and test_history_deals_get_filter into one parametrized test_history_get_filters covering both entities against the shared filter matrix. Also fold the redundant detect_and_convert_time_to_datetime dict/list-return checks into the main decorator test (strengthening its assertions instead), drop the empty-DataFrame case from test_set_index_if_possible_decorator since it duplicates test_orders_get_as_df_empty_result_has_no_index, and parametrize test_market_book_get_as_dicts by skip_to_datetime.
Split test_inheritance_behavior into a parametrized test_inheritance_exposes_expected_methods (one case per inherited/own method name) and a focused test_inheritance_behavior covering parent initialize/last_error behavior. Remove test_detect_and_convert_time_decorator, whose dict/list skip-vs-convert branches are now fully covered by test_symbol_info_dict_methods_with_skip_to_datetime and test_get_as_dicts_skip_to_datetime.
dceoy
left a comment
There was a problem hiding this comment.
LGTM. I reviewed the diff with a focus on semantic equivalence of the parametrized test refactor and did not find any blocking issues.
The parametrized replacements preserve the important assertions for orders/positions DataFrame conversion, history filters, *_as_dicts time conversion behavior, copy method index_keys, inherited methods, and decorator behavior. CI is also green: pytest, ruff, pyright, and CodeQL all completed successfully.
Non-blocking note: this is effectively a test-suite refactor, while pyproject.toml and uv.lock bump the package version from 1.0.4 to 1.1.0. Keep that only if this PR is intentionally preparing a release; otherwise consider reverting the version bump to keep release metadata separate from test-only maintenance.
Summary
Consolidates multiple similar test methods into parametrized test cases across the test suite, reducing code duplication and improving maintainability. This refactoring applies the DRY principle to test code while maintaining full coverage of the tested functionality.
Key Changes
test_dataframe.py:
test_orders_get_with_dataandtest_positions_get_with_datainto a single parametrizedtest_orders_positions_get_with_datamethod*_as_dictstest methods (symbols_get_as_dicts,orders_get_as_dicts,positions_get_as_dicts,history_orders_get_as_dicts,history_deals_get_as_dicts) into a single parametrizedtest_get_as_dicts_skip_to_datetimemethodcopy_rates_from_as_dfandcopy_ticks_from_as_dfindex_keys tests intotest_copy_methods_with_index_keystest_dataframe_methods_with_index_keysinto two focused parametrized tests:test_orders_positions_get_as_df_with_index_keysandtest_copy_methods_with_index_keys_MockSymbolRowclass to replace inline mock definitionstest_symbols_total(redundant coverage)test_mt5.py:
test_orders_getandtest_positions_getinto a single parametrizedtest_orders_positions_getmethodtest_utils.py:
test_decorator_with_other_result_typevariants) into a single parametrized test methodpyproject.toml:
Implementation Details
pytest.paramwith descriptiveidarguments for clarity in test outputhttps://claude.ai/code/session_01PLmm9eBm4WRiLfCcQCuqae