Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: Move autouse fixtures to test root
  • Loading branch information
eddiebergman committed Oct 17, 2024
commit 9266a7f0a80eab049b923ac7ad75d3a9fd134566
65 changes: 50 additions & 15 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,37 +195,41 @@ def pytest_addoption(parser):
def _expected_static_cache_state(root_dir: Path) -> list[Path]:
_c_root_dir = root_dir / "org" / "openml" / "test"
res_paths = [root_dir, _c_root_dir]

for _d in ["datasets", "tasks", "runs", "setups"]:
res_paths.append(_c_root_dir / _d)

for _id in ["-1","2"]:
for _id in ["-1", "2"]:
tmp_p = _c_root_dir / "datasets" / _id
res_paths.extend([
tmp_p / "dataset.arff",
tmp_p / "features.xml",
tmp_p / "qualities.xml",
tmp_p / "description.xml",
])
res_paths.extend(
[
tmp_p / "dataset.arff",
tmp_p / "features.xml",
tmp_p / "qualities.xml",
tmp_p / "description.xml",
]
)

res_paths.append(_c_root_dir / "datasets" / "30" / "dataset_30.pq")
res_paths.append(_c_root_dir / "runs" / "1" / "description.xml")
res_paths.append(_c_root_dir / "setups" / "1" / "description.xml")

for _id in ["1", "3", "1882"]:
tmp_p = _c_root_dir / "tasks" / _id
res_paths.extend([
tmp_p / "datasplits.arff",
tmp_p / "task.xml",
])

res_paths.extend(
[
tmp_p / "datasplits.arff",
tmp_p / "task.xml",
]
)

return res_paths


def assert_static_test_cache_correct(root_dir: Path) -> None:
for p in _expected_static_cache_state(root_dir):
assert p.exists(), f"Expected path {p} does not exist"


@pytest.fixture(scope="class")
def long_version(request):
Expand All @@ -247,3 +251,34 @@ def verify_cache_state(test_files_directory) -> None:
assert_static_test_cache_correct(test_files_directory)
yield
assert_static_test_cache_correct(test_files_directory)


@pytest.fixture(autouse=True)
def as_robot():
policy = openml.config.retry_policy
n_retries = openml.config.connection_n_retries
openml.config.set_retry_policy("robot", n_retries=20)
yield
openml.config.set_retry_policy(policy, n_retries)


@pytest.fixture(autouse=True)
def with_test_server():
openml.config.start_using_configuration_for_example()
yield
openml.config.stop_using_configuration_for_example()


@pytest.fixture(autouse=True)
def with_test_cache(test_files_directory, request):
if not test_files_directory.exists():
raise ValueError(
f"Cannot find test cache dir, expected it to be {test_files_directory!s}!",
)
_root_cache_directory = openml.config._root_cache_directory
tmp_cache = test_files_directory / request.node.name
openml.config.set_root_cache_directory(tmp_cache)
yield
openml.config.set_root_cache_directory(_root_cache_directory)
if tmp_cache.exists():
shutil.rmtree(tmp_cache)
31 changes: 0 additions & 31 deletions tests/test_utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,6 @@
from openml.testing import _check_dataset


@pytest.fixture(autouse=True)
def as_robot():
policy = openml.config.retry_policy
n_retries = openml.config.connection_n_retries
openml.config.set_retry_policy("robot", n_retries=20)
yield
openml.config.set_retry_policy(policy, n_retries)


@pytest.fixture(autouse=True)
def with_test_server():
openml.config.start_using_configuration_for_example()
yield
openml.config.stop_using_configuration_for_example()


@pytest.fixture(autouse=True)
def with_test_cache(test_files_directory, request):
if not test_files_directory.exists():
raise ValueError(
f"Cannot find test cache dir, expected it to be {test_files_directory!s}!",
)
_root_cache_directory = openml.config._root_cache_directory
tmp_cache = test_files_directory / request.node.name
openml.config.set_root_cache_directory(tmp_cache)
yield
openml.config.set_root_cache_directory(_root_cache_directory)
if tmp_cache.exists():
shutil.rmtree(tmp_cache)


@pytest.fixture()
def min_number_tasks_on_test_server() -> int:
"""After a reset at least 1068 tasks are on the test server"""
Expand Down