Skip to content

Commit

Permalink
Activating session on fixture to try to speed up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Hartorn committed Sep 26, 2023
1 parent 6cff0b9 commit f3e4b21
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def preprocess_data(df: pd.DataFrame) -> pd.DataFrame:
return df


@pytest.fixture()
@pytest.fixture(scope="session")
def amazon_review_data() -> Dataset:
raw_data = preprocess_data(download_data(nrows=5000))
wrapped_data = Dataset(
Expand Down Expand Up @@ -88,7 +88,7 @@ def tokenizer(x):
return stems


@pytest.fixture()
@pytest.fixture(scope="session")
def amazon_review_model(amazon_review_data: Dataset) -> SKLearnModel:
x = amazon_review_data.df[[FEATURE_COLUMN_NAME]]
y = amazon_review_data.df[TARGET_COLUMN_NAME]
Expand Down
2 changes: 1 addition & 1 deletion python-client/tests/fixtures/diabetes__regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from giskard.ml_worker.utils.logging import Timer


@pytest.fixture()
@pytest.fixture(scope="session")
def linear_regression_diabetes_raw():
timer = Timer()
diabetes = datasets.load_diabetes()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def _bin_na_to_k(_df: pd.DataFrame) -> pd.DataFrame:
return df


@pytest.fixture()
@pytest.fixture(scope="session")
def drug_classification_data() -> Dataset:
# Download data.
fetch_from_ftp(DATA_URL, DATA_PATH)
Expand All @@ -63,7 +63,7 @@ def drug_classification_data() -> Dataset:
return wrapped_dataset


@pytest.fixture()
@pytest.fixture(scope="session")
def drug_classification_model(drug_classification_data) -> SKLearnModel:
x = drug_classification_data.df.drop(TARGET_NAME, axis=1)
y = drug_classification_data.df.Drug
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def get_labels(filename):
return dict(labels)


@pytest.fixture()
@pytest.fixture(scope="session")
def enron_data() -> Dataset:
logger.info("Fetching Enron Data")
df = pd.read_csv(path("test_data/enron_data.csv"), keep_default_na=False, na_values=["_GSK_NA_"])
Expand Down Expand Up @@ -127,7 +127,7 @@ def enron_test_data(enron_data):
return Dataset(df=pd.DataFrame(enron_data.df).drop(columns=["Target"]), target=None, column_types=input_types)


@pytest.fixture()
@pytest.fixture(scope="session")
def enron_model(enron_data) -> SKLearnModel:
timer = Timer()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def fraud_detection_data() -> Dataset:
return wrapped_dataset


@pytest.fixture()
@pytest.fixture(scope="session")
def fraud_detection_train_data() -> Dataset:
train_set, _ = preprocess_dataset(*read_dataset())
wrapped_dataset = Dataset(
Expand All @@ -157,7 +157,7 @@ def fraud_detection_train_data() -> Dataset:
return wrapped_dataset


@pytest.fixture()
@pytest.fixture(scope="session")
def fraud_detection_model(fraud_detection_train_data: Dataset) -> Model:
from lightgbm import LGBMClassifier

Expand Down
4 changes: 2 additions & 2 deletions python-client/tests/fixtures/german_credit_scoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
}


@pytest.fixture()
@pytest.fixture(scope="session")
def german_credit_data() -> Dataset:
logger.info("Reading german_credit_prepared.csv")
df = pd.read_csv(path("test_data/german_credit_prepared.csv"), keep_default_na=False, na_values=["_GSK_NA_"])
Expand Down Expand Up @@ -92,7 +92,7 @@ def german_credit_test_data(german_credit_data):
return Dataset(df=df, target=None, column_types=input_types)


@pytest.fixture()
@pytest.fixture(scope="session")
def german_credit_raw_model(german_credit_data):
timer = Timer()

Expand Down
4 changes: 2 additions & 2 deletions python-client/tests/fixtures/hotel_text__regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def load_data(**kwargs) -> pd.DataFrame:
return df


@pytest.fixture
@pytest.fixture(scope="session")
def hotel_text_data() -> Dataset:
fetch_from_ftp(DATA_URL, DATA_PATH)

Expand All @@ -56,7 +56,7 @@ def adapt_vectorizer_input(df: pd.DataFrame) -> Iterable:
return df


@pytest.fixture
@pytest.fixture(scope="session")
def hotel_text_model(hotel_text_data) -> SKLearnModel:
x = hotel_text_data.df[[FEATURE_COLUMN_NAME]]
y = hotel_text_data.df[TARGET_COLUMN_NAME]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def load_data() -> pd.DataFrame:
return df


@pytest.fixture()
@pytest.fixture(scope="session")
def medical_transcript_data() -> Dataset:
raw_data = load_data()
wrapped_data = Dataset(
Expand Down Expand Up @@ -85,7 +85,7 @@ def adapt_vectorizer_input(df: pd.DataFrame) -> Iterable:
return df


@pytest.fixture()
@pytest.fixture(scope="session")
def medical_transcript_model(medical_transcript_data: Dataset) -> SKLearnModel:
# Define final pipeline.
pipeline = Pipeline(
Expand Down
4 changes: 2 additions & 2 deletions python-client/tests/fixtures/pytorch_sst2.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from tests.utils import resource_dir


@pytest.fixture()
@pytest.fixture(scope="session")
def sst2_dev_data():
dev_datapipe = SST2(split="dev")
return pd.DataFrame(dev_datapipe, columns=["text", "label"])
Expand All @@ -24,7 +24,7 @@ def sst2_data(sst2_dev_data):
return Dataset(sst2_dev_data.head(), name="test dataset", target="label")


@pytest.fixture()
@pytest.fixture(scope="session")
def sst2_model(sst2_dev_data):
torch_softmax = nn.Softmax(dim=1)
device = "cuda" if torch.cuda.is_available() else "cpu"
Expand Down
2 changes: 1 addition & 1 deletion python-client/tests/fixtures/titanic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from giskard.demo import titanic


@pytest.fixture()
@pytest.fixture(scope="session")
def titanic_model_data_raw():
return titanic()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def model_predict(self, df: pd.DataFrame) -> np.ndarray:
return predicted_probabilities


@pytest.fixture()
@pytest.fixture(scope="session")
def tripadvisor_data() -> Dataset:
# Download dataset
df = load_dataset()
Expand All @@ -210,7 +210,7 @@ def tripadvisor_data() -> Dataset:
)


@pytest.fixture()
@pytest.fixture(scope="session")
def tripadvisor_model(tripadvisor_data: Dataset) -> Model:
# Load model.
model = DistilBertForSequenceClassification.from_pretrained(
Expand Down
4 changes: 2 additions & 2 deletions python-client/tests/fixtures/xboost_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
TARGET_COLUMN_NAME = "target"


@pytest.fixture()
@pytest.fixture(scope="session")
def breast_cancer_data() -> Dataset:
logger.info("Fetching Breast Cancer Data")
raw_data = load_breast_cancer(as_frame=True)
Expand All @@ -25,7 +25,7 @@ def breast_cancer_data() -> Dataset:
return Dataset(df, name="breast_cancer", target="target", column_types=column_types)


@pytest.fixture()
@pytest.fixture(scope="session")
def breast_cancer_model(breast_cancer_data: Dataset) -> Model:
X_train, X_test, y_train, y_test = train_test_split(
breast_cancer_data.df.loc[:, breast_cancer_data.df.columns != TARGET_COLUMN_NAME],
Expand Down

0 comments on commit f3e4b21

Please sign in to comment.