Skip to content

Commit

Permalink
Merge pull request #251 from juaml/chore/support-pytest8
Browse files Browse the repository at this point in the history
[MAINT]: Support `pytest >= 8.0.0`
  • Loading branch information
synchon authored Feb 14, 2024
2 parents 8d0fd89 + 73e8dab commit d1f915e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 53 deletions.
1 change: 1 addition & 0 deletions docs/changes/newsfragments/251.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove ``pytest-lazy-fixture`` and enable support for ``pytest >= 8.0.0`` by `Synchon Mandal`_
8 changes: 4 additions & 4 deletions julearn/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def X_types_iris(request: FixtureRequest) -> Optional[Dict]:


@fixture(params=["rf", "svm", "gauss", "ridge"], scope="function")
def models_all_problem_types(request: FixtureRequest) -> str:
def model(request: FixtureRequest) -> str:
"""Return different models that work with classification and regression.
Parameters
Expand All @@ -149,7 +149,7 @@ def models_all_problem_types(request: FixtureRequest) -> str:


@fixture(params=["regression", "classification"], scope="function")
def all_problem_types(request: FixtureRequest) -> str:
def problem_type(request: FixtureRequest) -> str:
"""Return different problem types.
Parameters
Expand All @@ -160,7 +160,7 @@ def all_problem_types(request: FixtureRequest) -> str:
Returns
-------
str
The problem type (one of {"regression", "classification"}).
The problem type.
"""

Expand Down Expand Up @@ -245,7 +245,7 @@ def get(step: str) -> Dict:
],
scope="function",
)
def preprocessing(request: FixtureRequest) -> Union[str, List[str]]:
def preprocess(request: FixtureRequest) -> Union[str, List[str]]:
"""Return different preprocessing steps.
Parameters
Expand Down
7 changes: 1 addition & 6 deletions julearn/models/tests/test_dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import pandas as pd
import pytest
from pytest import FixtureRequest, fixture
from pytest_lazyfixture import lazy_fixture
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import ShuffleSplit, train_test_split

Expand Down Expand Up @@ -64,7 +63,7 @@
],
scope="module",
)
def all_deslib_algorithms(request: FixtureRequest) -> str:
def algo_name(request: FixtureRequest) -> str:
"""Return different algorithms for the iris dataset features.
Parameters
Expand All @@ -81,10 +80,6 @@ def all_deslib_algorithms(request: FixtureRequest) -> str:
return request.param


@pytest.mark.parametrize(
"algo_name",
[lazy_fixture("all_deslib_algorithms")],
)
@pytest.mark.skip("Deslib is not compatible with new python. Waiting for PR.")
def test_algorithms(
df_iris: pd.DataFrame,
Expand Down
41 changes: 8 additions & 33 deletions julearn/pipeline/test/test_pipeline_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
# License: AGPL

import warnings
from typing import Callable, Dict, List
from typing import Callable, Dict, List, Union

import pandas as pd
import pytest
from pytest_lazyfixture import lazy_fixture
from sklearn.dummy import DummyClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import GridSearchCV, RandomizedSearchCV
Expand All @@ -23,24 +22,16 @@
from julearn.transformers import get_transformer


@pytest.mark.parametrize(
"model,preprocess,problem_type",
[
lazy_fixture(
["models_all_problem_types", "preprocessing", "all_problem_types"]
)
],
)
def test_construction_working(
model: str, preprocess: List[str], problem_type: str
model: str, preprocess: Union[str, List[str]], problem_type: str
) -> None:
"""Test that the pipeline constructions works as expected.
Parameters
----------
model : str
The model to test.
preprocess : List[str]
preprocess : str or list of str
The preprocessing steps to test.
problem_type : str
The problem type to test.
Expand Down Expand Up @@ -77,19 +68,11 @@ def test_construction_working(
assert len(preprocess) + 2 == len(pipeline.steps)


@pytest.mark.parametrize(
"model,preprocess,problem_type",
[
lazy_fixture(
["models_all_problem_types", "preprocessing", "all_problem_types"]
)
],
)
def test_fit_and_transform_no_error(
X_iris: pd.DataFrame, # noqa: N803
y_iris: pd.Series,
model: str,
preprocess: List[str],
preprocess: Union[str, List[str]],
problem_type: str,
) -> None:
"""Test that the pipeline fit and transform does not give an error.
Expand All @@ -102,7 +85,7 @@ def test_fit_and_transform_no_error(
The iris dataset target variable.
model : str
The model to test.
preprocess : List[str]
preprocess : str or list of str
The preprocessing steps to test.
problem_type : str
The problem type to test.
Expand All @@ -117,18 +100,10 @@ def test_fit_and_transform_no_error(
pipeline[:-1].transform(X_iris)


@pytest.mark.parametrize(
"model,preprocess,problem_type",
[
lazy_fixture(
["models_all_problem_types", "preprocessing", "all_problem_types"]
),
],
)
def test_hyperparameter_tuning(
X_types_iris: Dict[str, List[str]], # noqa: N803
model: str,
preprocess: List[str],
preprocess: Union[str, List[str]],
problem_type: str,
get_tuning_params: Callable,
search_params: Dict[str, List],
Expand All @@ -137,11 +112,11 @@ def test_hyperparameter_tuning(
Parameters
----------
X_types_iris : Dict[str, List[str]]
X_types_iris : dict
The iris dataset features types.
model : str
The model to test.
preprocess : List[str]
preprocess : str or list of str
The preprocessing steps to test.
problem_type : str
The problem type to test.
Expand Down
13 changes: 3 additions & 10 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,8 @@ python =
[testenv]
skip_install = false
deps =
pytest<8.0.0
pytest-lazy-fixture
pytest
seaborn
deslib
panel>=1.0.0b1
bokeh>=3.0.0
param
commands =
pytest

Expand All @@ -39,8 +34,7 @@ commands =
[testenv:test]
skip_install = false
deps =
pytest<8.0.0
pytest-lazy-fixture
pytest
seaborn
deslib
panel>=1.0.0b1
Expand All @@ -52,8 +46,7 @@ commands =
[testenv:coverage]
skip_install = false
deps =
pytest<8.0.0
pytest-lazy-fixture
pytest
pytest-cov
seaborn
deslib
Expand Down

0 comments on commit d1f915e

Please sign in to comment.