Skip to content

Commit 45b1eb0

Browse files
authored
Speed up CI testing (#163)
* Speed up tests by disabling slow tests.
1 parent 5889a04 commit 45b1eb0

File tree

7 files changed

+57
-15
lines changed

7 files changed

+57
-15
lines changed

hpobench/util/test_utils.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import os
2+
3+
CONST_RUN_ALL_TESTS_ENV_VAR = 'HPOBENCH_RUN_EXPENSIVE_TESTS'
4+
DEFAULT_SKIP_MSG = 'Skip this test due to time limitations'
5+
6+
7+
def check_run_all_tests():
8+
""" Helper function: Check if all tests should run. """
9+
return os.environ.get(CONST_RUN_ALL_TESTS_ENV_VAR, 'false').lower() == 'true'
10+
11+
12+
def enable_all_tests():
13+
"""
14+
Some tests are quite expensive. We control if all runs should be executed by this
15+
environment variable.
16+
"""
17+
os.environ[CONST_RUN_ALL_TESTS_ENV_VAR] = 'true'
18+
19+
20+
def disable_all_tests():
21+
"""
22+
This function disables the evaluation of all test functions.
23+
"""
24+
os.environ[CONST_RUN_ALL_TESTS_ENV_VAR] = 'false'

tests/test_data_manager.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
import shutil
2-
from multiprocessing import Pool
3-
42
import pytest
3+
from multiprocessing import Pool
54

65
import hpobench
76
from hpobench.util.data_manager import NASBench_201Data, YearPredictionMSDData, ProteinStructureData, BostonHousingData
8-
skip_message = 'We currently skip this test because it takes too much time.'
7+
from hpobench.util.test_utils import DEFAULT_SKIP_MSG, check_run_all_tests
98

109

11-
@pytest.mark.skip(reason=skip_message)
10+
@pytest.mark.skipif(not check_run_all_tests(), reason=DEFAULT_SKIP_MSG)
1211
def test_nasbench_201_load_thread_safe():
1312
shutil.rmtree(hpobench.config_file.data_dir / "nasbench_201", ignore_errors=True)
1413
function = lambda: NASBench_201Data(dataset='cifar100').load()
1514
with Pool(3) as pool:
1615
pool.map(function, [])
1716

1817

19-
@pytest.mark.skip(reason=skip_message)
18+
@pytest.mark.skipif(not check_run_all_tests(), reason=DEFAULT_SKIP_MSG)
2019
def test_nasbench_201_init():
2120

2221
data_manager = NASBench_201Data(dataset='cifar100')
@@ -30,7 +29,7 @@ def test_nasbench_201_init():
3029
assert data_manager._save_dir.exists()
3130

3231

33-
@pytest.mark.skip(reason=skip_message)
32+
@pytest.mark.skipif(not check_run_all_tests(), reason=DEFAULT_SKIP_MSG)
3433
def test_nasbench_201_load():
3534

3635
shutil.rmtree(hpobench.config_file.data_dir / "nasbench_201", ignore_errors=True)

tests/test_mo_cnn.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import pytest
2+
from hpobench.util.test_utils import DEFAULT_SKIP_MSG, check_run_all_tests
23

34

5+
@pytest.mark.skipif(not check_run_all_tests(), reason=DEFAULT_SKIP_MSG)
46
def test_mo_cnn_seeding():
57
from hpobench.container.benchmarks.mo.cnn_benchmark import FlowerCNNBenchmark
68
b1 = FlowerCNNBenchmark(rng=0)

tests/test_nasbench_201.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
import logging
2-
logging.basicConfig(level=logging.DEBUG)
31
import pytest
42

53
from hpobench.container.benchmarks.nas.nasbench_201 import ImageNetNasBench201Benchmark, Cifar100NasBench201Benchmark, \
64
Cifar10ValidNasBench201Benchmark
75
from hpobench.benchmarks.nas.nasbench_201 import \
86
Cifar10ValidNasBench201MOBenchmark as LocalCifar10ValidNasBench201MOBenchmark
97
from hpobench.util.container_utils import disable_container_debug, enable_container_debug
10-
11-
skip_message = 'We currently skip this test because it takes too much time.'
8+
from hpobench.util.test_utils import DEFAULT_SKIP_MSG, check_run_all_tests
129

1310

1411
@pytest.fixture(scope='module')
@@ -18,7 +15,7 @@ def enable_debug():
1815
disable_container_debug()
1916

2017

21-
@pytest.mark.skip(reason=skip_message)
18+
@pytest.mark.skipif(not check_run_all_tests(), reason=DEFAULT_SKIP_MSG)
2219
def test_nasbench201_cifar10valid(enable_debug):
2320

2421
b = Cifar10ValidNasBench201Benchmark(rng=0)
@@ -53,7 +50,7 @@ def test_nasbench201_cifar10valid(enable_debug):
5350
result = b.objective_function_test(configuration=config, fidelity={'epoch': 10})
5451

5552

56-
@pytest.mark.skip(reason=skip_message)
53+
@pytest.mark.skipif(not check_run_all_tests(), reason=DEFAULT_SKIP_MSG)
5754
def test_nasbench201_cifar100(enable_debug):
5855
b = Cifar100NasBench201Benchmark(rng=0)
5956

@@ -73,7 +70,7 @@ def test_nasbench201_cifar100(enable_debug):
7370
assert result['info']['valid_cost'] == result['cost']
7471

7572

76-
@pytest.mark.skip(reason=skip_message)
73+
@pytest.mark.skipif(not check_run_all_tests(), reason=DEFAULT_SKIP_MSG)
7774
def test_nasbench201_Image(enable_debug):
7875
b = ImageNetNasBench201Benchmark(rng=0)
7976
config = {'1<-0': 'nor_conv_1x1',

tests/test_pybnn.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1+
import sys
12
import pytest
23

34
from hpobench.container.benchmarks.ml.pybnn import BNNOnToyFunction, BNNOnBostonHousing, BNNOnProteinStructure, \
45
BNNOnYearPrediction
56

6-
import logging
7-
logging.basicConfig(level=logging.DEBUG)
87
from hpobench.util.container_utils import enable_container_debug
8+
from hpobench.util.test_utils import check_run_all_tests, DEFAULT_SKIP_MSG
9+
910
enable_container_debug()
11+
MSG = 'Skip this test for new (>3.9) python versions. ' \
12+
'The paramnet benchmarks require an specific old scikit learn version. This version however does not work under ' \
13+
'python 3.10. Therefore we skip this test. The containerized version does still work under 3.10.'
1014

1115

16+
@pytest.mark.skipif(sys.version_info > (3, 9), reason=MSG)
1217
def test_bnn_init():
1318
benchmark = BNNOnToyFunction(rng=1)
1419

@@ -58,6 +63,7 @@ def test_bnn_boston_housing():
5863
assert test_result['info']['fidelity']['budget'] == 1000
5964

6065

66+
@pytest.mark.skipif(not check_run_all_tests(), reason=DEFAULT_SKIP_MSG)
6167
def test_bnn_protein():
6268
benchmark = BNNOnProteinStructure(rng=1)
6369
test_result = simple_call(benchmark)
@@ -66,6 +72,7 @@ def test_bnn_protein():
6672
assert test_result['info']['fidelity']['budget'] == 1000
6773

6874

75+
@pytest.mark.skipif(not check_run_all_tests(), reason=DEFAULT_SKIP_MSG)
6976
def test_year_pred():
7077
benchmark = BNNOnYearPrediction(rng=1)
7178
test_result = simple_call(benchmark)

tests/test_utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,15 @@ def test_debug_level():
105105

106106
disable_container_debug()
107107
assert os.environ['HPOBENCH_DEBUG'] == 'false'
108+
109+
110+
def test_test_utils():
111+
from hpobench.util.test_utils import DEFAULT_SKIP_MSG, enable_all_tests, disable_all_tests, check_run_all_tests
112+
113+
assert isinstance(DEFAULT_SKIP_MSG, str)
114+
115+
enable_all_tests()
116+
assert check_run_all_tests()
117+
118+
disable_all_tests()
119+
assert not check_run_all_tests()

tests/test_whitebox.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def test_whitebox_with_container():
6363
assert np.isclose(test_loss, 0.43636, atol=0.001)
6464

6565

66+
@pytest.mark.skipif(skip_container_test, reason="Requires singularity and flask")
6667
def test_cartpole():
6768
from hpobench.container.benchmarks.rl.cartpole import CartpoleReduced as Benchmark
6869
b = Benchmark(container_name='cartpole',

0 commit comments

Comments
 (0)