Python: fix(tests): split pytest.raises blocks to eliminate dead code#5171
Python: fix(tests): split pytest.raises blocks to eliminate dead code#5171Bahtya wants to merge 1 commit intomicrosoft:mainfrom
Conversation
pytest.raises exits after the first exception, so multiple statements
in a single block are dead code. Split each multi-statement
pytest.raises block into separate blocks so all error cases are
actually tested.
Also remove the dead detect_media_type_from_base64(data_str="") call
which does not raise (base64.b64decode("") is valid).
Fixes microsoft#5115
Signed-off-by: bahtya <bahtyar153@qq.com>
|
@Bahtya, thanks a lot for your PR! I don’t think removing the test case is the right approach here. If the test was added, it likely represents the intended behavior. In that case, the implementation should probably be updated to make the test pass. Alternatively, it would be good to get confirmation from a maintainer (for example, @moonbox3) before proceeding this way, as outlined in the contribution guidelines. |
as far as I can see, this does not remove any tests, just ensures that each check actually runs. |
It removes detect_media_type_from_base64(data_str="") case. According to the original test-suit: the empty string has to caus "Invalid base64 data provided." error. |
Problem
Multiple
with pytest.raises(...)blocks intest_types.pycontain more than one statement. Sincepytest.raisesexits after the first exception, all subsequent statements are dead code that never execute, creating a false sense of test coverage.Fix
Split each multi-statement
pytest.raisesblock into separate blocks so all error cases are actually tested.Also removed the dead
detect_media_type_from_base64(data_str="")call from the base64 error block, asbase64.b64decode("")is valid and does not raise.Fixes #5115