-
-
Notifications
You must be signed in to change notification settings - Fork 103
/
conftest.py
47 lines (33 loc) · 1.21 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import pytest
import functools
import matplotlib
import numpy as np
import pandas as pd
from sklearn import datasets
@pytest.fixture(autouse=True)
def disable_plot(monkeypatch):
# Patch plt.show to not halt testing flow, by making it not block
# function execution.
# patch = functools.partial(matplotlib.pyplot.show, block=False)
def patch():
pass
monkeypatch.setattr(matplotlib.pyplot, "show", patch)
@pytest.fixture
def iris_df():
# Use iris dataset as example when needed.
# Add one made-up categorical column to create a nom-nom relationship.
iris = datasets.load_iris()
target = ["C{}".format(i) for i in iris.target]
rng = np.random.default_rng(2207)
extra = rng.choice(list("ABCDE"), size=len(target))
extra = pd.DataFrame(data=extra, columns=["extra"])
X = pd.DataFrame(data=iris.data, columns=iris.feature_names)
y = pd.DataFrame(data=target, columns=["target"])
df = pd.concat([X, extra, y], axis=1)
return df
@pytest.fixture(autouse=True)
def add_iris(doctest_namespace, iris_df):
# Add iris dataset to namespace
# This fixture is provided with autouse so that
# the doctests can use it
doctest_namespace["iris_df"] = iris_df