Parametrize `test_classifications`
Refs #234
parametrize
(time tox -- tests/test_elements_worker/test_classifications.py
)
With parametrize:
real 0m26,853s
user 0m9,453s
sys 0m0,800s
Without:
real 0m15,225s
user 0m5,799s
sys 0m0,414s
Merge request reports
Activity
added P3 label
assigned to @mblanco
- Resolved by Yoann Schneider
Can you upload both tox output? Tox may say which part is slow
requested review from @yschneider
I think we should still do the change, even if it appears to take longer. That's because we execute twice more test cases in reality. We should compare the parametrize execution with the following implementation of
tests/test_elements_worker/test_classifications.py::test_create_classification_wrong_high_confidence
More comparable version
def test_create_classification_wrong_high_confidence1(mock_elements_worker): mock_elements_worker.classes = {"a_class": "0000"} elt = Element({"id": "12341234-1234-1234-1234-123412341234"}) with pytest.raises( AssertionError, match="high_confidence shouldn't be null and should be of type bool", ): mock_elements_worker.create_classification( element=elt, ml_class="a_class", confidence=0.42, high_confidence=None, ) def test_create_classification_wrong_high_confidence2(mock_elements_worker): mock_elements_worker.classes = {"a_class": "0000"} elt = Element({"id": "12341234-1234-1234-1234-123412341234"}) with pytest.raises( AssertionError, match="high_confidence shouldn't be null and should be of type bool", ): mock_elements_worker.create_classification( element=elt, ml_class="a_class", confidence=0.42, high_confidence="wrong high_confidence", )
The current implementation of unit tests is flawed, test case should test 1 thing at a time, one input and one expected input.
Using parametrize makes it easier to do that and removes code duplication. We should still strive for the fastest test execution though.
- Resolved by Yoann Schneider
- Resolved by Manon Blanco
added 15 commits
-
166541b8...2ed51266 - 12 commits from branch
master
- 0db7bf2c - Parametrize `test_classifications`
- 402af409 - V2
- 38431d3f - Add comment
Toggle commit list-
166541b8...2ed51266 - 12 commits from branch
enabled an automatic merge when the pipeline for 38431d3f succeeds