Skip to content

Commit

Permalink
Fix flaky ObjectClassificationGui test (ilastik#2911)
Browse files Browse the repository at this point in the history
this test was flaky due to so many features in training - fixing the
seed for the RF training should fix this.

In the test class the following comparisons against of exported data
to reference data would fail occasionally.

Also removed some unused imports.
  • Loading branch information
k-dominik authored Sep 27, 2024
1 parent 601ba4f commit 796dfb2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
24 changes: 21 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
from pathlib import Path
import os
import shutil
import tempfile
import threading
import time
import queue
import sys
import warnings
import platform
import itertools
Expand Down Expand Up @@ -358,3 +355,24 @@ def cacheMemoryManager(monkeypatch):
mem_manager = _CacheMemoryManager()
monkeypatch.setattr(lazyflow.operators.cacheMemoryManager, "_cache_memory_manager", mem_manager)
return mem_manager


@pytest.fixture()
def reliable_vigra_train_rf_seed(monkeypatch):
"""
Can be used in test functions that involve invoking
`vigra.learning.RandomForest.learnRF` along the way. This will set
the randomSeed parameter in that function to 42.
Relies on `learnRF` being called only with parameters trainData and trainLabels.
"""
import vigra

_learn_orig = vigra.learning.RandomForest.learnRF
randomSeed = 42

# Note: can't use a partial there, the function doesn't like kwargs
monkeypatch.setattr(
vigra.learning.RandomForest,
"learnRF",
lambda self, trainData, trainLabels: _learn_orig(self, trainData, trainLabels, randomSeed),
)
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import h5py
import numpy
import pytest

from ilastik.workflows import ObjectClassificationWorkflowPrediction
from ilastik.applets.dataSelection.opDataSelection import FilesystemDatasetInfo
Expand Down Expand Up @@ -364,6 +365,7 @@ def impl():
# Run this test from within the shell event loop
self.exec_in_shell(impl)

@pytest.mark.usefixtures("reliable_vigra_train_rf_seed")
def test_05_live_update_mode(self):
def impl():
shell = self.shell
Expand Down

0 comments on commit 796dfb2

Please sign in to comment.