Skip to content
Snippets Groups Projects

Parametrize `test_classifications`

Merged Manon Blanco requested to merge parametrize-classifications-tests into master
All threads resolved!

Refs #234

:warning: It seems slower with 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
Edited by Manon Blanco

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • added P3 label

  • assigned to @mblanco

  • Manon Blanco changed the description

    changed the description

  • Yoann Schneider requested review from @yschneider

    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.

  • Yoann Schneider resolved all threads

    resolved all threads

  • Yoann Schneider
  • Manon Blanco added 1 commit

    added 1 commit

    Compare with previous version

  • Manon Blanco resolved all threads

    resolved all threads

  • Yoann Schneider approved this merge request

    approved this merge request

  • Yoann Schneider added 15 commits

    added 15 commits

    Compare with previous version

  • Yoann Schneider enabled an automatic merge when the pipeline for 38431d3f succeeds

    enabled an automatic merge when the pipeline for 38431d3f succeeds

  • Please register or sign in to reply
    Loading