Implementation:Scikit learn Scikit learn Conftest
| Knowledge Sources | |
|---|---|
| Domains | Machine Learning, Testing, Configuration |
| Last Updated | 2026-02-08 15:00 GMT |
Overview
Concrete pytest configuration module for the scikit-learn test suite provided by scikit-learn.
Description
The conftest module configures the pytest test environment for scikit-learn. It defines fixtures for dataset fetchers (e.g., fetch_20newsgroups, fetch_california_housing), handles warning filters, manages thread pool limits, configures BLAS settings, and provides skip conditions for 32-bit platforms and network-dependent tests. It also supports parallel test execution via pytest-run-parallel.
Usage
This module is automatically loaded by pytest when running scikit-learn tests. It provides fixtures and hooks that control test execution behavior, dataset caching, and platform-specific test skipping.
Code Reference
Source Location
- Repository: scikit-learn
- File: sklearn/conftest.py
Signature
def raccoon_face_or_skip():
...
dataset_fetchers = {
"fetch_20newsgroups_fxt": fetch_20newsgroups,
"fetch_california_housing_fxt": fetch_california_housing,
...
}
@pytest.fixture
def pyplot():
...
def pytest_collection_modifyitems(config, items):
...
def pytest_configure(config):
...
Import
# Automatically loaded by pytest; not imported directly
# Fixtures are available to all tests in the sklearn package
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| config | pytest.Config | Yes | Pytest configuration object (provided by pytest) |
| items | list | Yes | List of collected test items (provided by pytest) |
Outputs
| Name | Type | Description |
|---|---|---|
| fixtures | various | Dataset fixtures, pyplot fixture, and global configuration for tests |
Usage Examples
Basic Usage
# In a test file within sklearn/tests/
def test_with_dataset(fetch_california_housing_fxt):
data = fetch_california_housing_fxt
assert data is not None
def test_plotting(pyplot):
# pyplot fixture ensures matplotlib is properly cleaned up
import matplotlib.pyplot as plt
fig, ax = plt.subplots()