Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
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
17 changes: 17 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
- check-nightly-ci
- changed-files
- checks
- local-runner-tests
- clang-tidy
- conda-cpp-build
- conda-cpp-tests
Expand Down Expand Up @@ -286,6 +287,22 @@ jobs:
# Main builds seed this cache. PR merge refs can restore it but should not create
# duplicate archives that are inaccessible to other PRs.
pre-commit-cache-read-only: true
local-runner-tests:
permissions:
actions: read
contents: read
id-token: write
packages: read
pull-requests: read
secrets: inherit # zizmor: ignore[secrets-inherit]
uses: rapidsai/shared-workflows/.github/workflows/custom-job.yaml@main
with:
build_type: pull-request
node_type: "cpu8"
arch: "amd64"
container_image: "rapidsai/ci-conda:27.02-latest"
script: "ci/test_local_runners.sh"
artifact-name: local-runner-tests
clang-tidy:
needs: checks
permissions:
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ cpp/Doxyfile
compile_commands.json
.clangd/

# generally prefer 'pyproject.toml' to 'pytest.ini' for pytest options
# Prefer pyproject.toml; allow the isolated runner regression-test config.
# ref: https://github.com/NVIDIA/cuml/pull/6201
pytest.ini
!python/cuml/cuml_accel_tests/upstream/pytest.ini
!ci/tests/pytest.ini

# testing
python/cuml/cuml_accel_tests/upstream/umap/umap-upstream
Expand Down
37 changes: 6 additions & 31 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,24 +116,8 @@ If you want a list of the available C++ tests:
$ ctest --test-dir cpp/build -N
```

To run all Python tests, including multi-GPU algorithms, from the repo root:
```bash
$ cd python
$ pytest -v
```

To run only single-GPU algorithm tests:

```bash
$ pytest --ignore=cuml/tests/dask --ignore=cuml/tests/test_nccl.py
```

If you want a list of the available Python tests:
```bash
$ pytest cuml/tests --collect-only
```

**Note:** Some tests require `xgboost`. If running tests in conda devcontainers, you must install the `xgboost` conda package manually. See `dependencies.yaml` for version information.
For Python tests and focused local test execution, see
[Running Tests](docs/source/developer_guide/python/development.md#running-tests).

### Manual Process

Expand Down Expand Up @@ -236,23 +220,14 @@ From the repository root:
$ python -m pip install --no-build-isolation --no-deps --config-settings rapidsai.disable-cuda=true python/cuml
```

To run Python tests (optional):

```bash
$ cd python
$ pytest -v
```

To run only single-GPU algorithm tests:
To run Python tests from the repository root:

```bash
$ pytest --ignore=cuml/tests/dask --ignore=cuml/tests/test_nccl.py
pytest -v
```

If you want a list of the available tests:
```bash
$ pytest cuml/tests --collect-only
```
See the [developer testing guide](docs/source/developer_guide/python/development.md#running-tests)
for focused selections and other suites.

### Custom Build Options

Expand Down
64 changes: 64 additions & 0 deletions ci/cuml_pytest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

"""Repository-local pytest defaults, shared by developers and CI adapters."""

import copy
from pathlib import Path

import pytest

REPO = Path(__file__).resolve().parents[1]
PYTHON = REPO / "python/cuml"


def pytest_addoption(parser):
group = parser.getgroup("cuML options")
group.addoption(
"--cuml-suite",
choices=(
"standard",
"dask",
"accel",
"cudf-pandas",
),
default="standard",
help=(
"Test suite and execution configuration. "
"standard (default) runs cuML's single-GPU Python tests, excluding "
"Dask and accelerator suites. "
"Explicit pytest targets replace the default collection target."
),
)


@pytest.hookimpl(tryfirst=True)
def pytest_load_initial_conftests(early_config, parser, args):
options = parser.parse_known_args(args)
suite = options.cuml_suite
targets = {
"standard": PYTHON / "tests",
"dask": PYTHON / "tests/dask",
"accel": PYTHON / "cuml_accel_tests",
"cudf-pandas": PYTHON / "tests",
}
# Let pytest parse its own arguments: -k/-m/-n and their values are not
# collection targets. Do not append a default to explicit selections.
if not options.file_or_dir:
args.append(str(targets[suite]))
if suite in ("standard", "cudf-pandas"):
args.append(f"--ignore={PYTHON / 'tests/dask'}")
Comment thread
csadorf marked this conversation as resolved.
Resolved
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
if suite == "cudf-pandas":
early_config.pluginmanager.import_plugin("cudf.pandas")
from cudf.pandas import install

install()
_refresh_initial_args(early_config, parser, args)


def _refresh_initial_args(config, parser, args):
# Initial conftest discovery uses the pre-parsed namespace, not args.
# Keep both in sync so newly selected suites load their conftests early.
config.known_args_namespace = parser.parse_known_args(
args, namespace=copy.copy(config.known_args_namespace)
)
8 changes: 4 additions & 4 deletions ci/run_cuml_dask_pytests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

# Support invoking run_cuml_dask_pytests.sh outside the script directory
cd "$(dirname "$(realpath "${BASH_SOURCE[0]}")")"/../python/cuml/tests/dask || exit 1

python -m pytest --cache-clear --durations=100 --durations-min=1 "$@" .
set -euo pipefail
REPO=$(dirname "$(dirname "$(realpath "${BASH_SOURCE[0]}")")")
exec python -m pytest -c "${REPO}/pyproject.toml" --cuml-suite=dask \
--cache-clear --durations=100 --durations-min=1 "$@"
8 changes: 4 additions & 4 deletions ci/run_cuml_integration_pytests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

# Support invoking run_cuml_singlegpu_pytests.sh outside the script directory
cd "$(dirname "$(realpath "${BASH_SOURCE[0]}")")"/../python/cuml/tests || exit 1

python -m pytest -p cudf.pandas --cache-clear --durations=100 --durations-min=1 --ignore=dask "$@" --quick_run .
set -euo pipefail
REPO=$(dirname "$(dirname "$(realpath "${BASH_SOURCE[0]}")")")
exec python -m pytest -c "${REPO}/pyproject.toml" --cuml-suite=cudf-pandas \
--cache-clear --durations=100 --durations-min=1 --quick_run "$@"
8 changes: 4 additions & 4 deletions ci/run_cuml_singlegpu_accel_pytests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

# Support invoking run_cuml_singlegpu_accel_pytests.sh outside the script directory
cd "$(dirname "$(realpath "${BASH_SOURCE[0]}")")"/../python/cuml/cuml_accel_tests || exit 1

python -m pytest --cache-clear --durations=100 --durations-min=1 "$@" .
set -euo pipefail
REPO=$(dirname "$(dirname "$(realpath "${BASH_SOURCE[0]}")")")
exec python -m pytest -c "${REPO}/pyproject.toml" --cuml-suite=accel \
--cache-clear --durations=100 --durations-min=1 "$@"
8 changes: 4 additions & 4 deletions ci/run_cuml_singlegpu_pytests.sh

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We rely on these ci/run_* files to have a way to invoke that tests that isn't tightly coupled to being on GitHub in cuML's open source CI.

That's useful in local development, hardware bringup, DLFW builds, etc.

That's why they were introduced in the first place: #5761

Can we please keep these?

cross-ref: rapidsai/build-planning#269

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

# Support invoking run_cuml_singlegpu_pytests.sh outside the script directory
cd "$(dirname "$(realpath "${BASH_SOURCE[0]}")")"/../python/cuml/tests || exit 1

python -m pytest --cache-clear --durations=100 --durations-min=1 --ignore=dask "$@" .
set -euo pipefail
REPO=$(dirname "$(dirname "$(realpath "${BASH_SOURCE[0]}")")")
exec python -m pytest -c "${REPO}/pyproject.toml" --cuml-suite=standard \
--cache-clear --durations=100 --durations-min=1 "$@"
20 changes: 20 additions & 0 deletions ci/test_local_runners.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash
# SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

# CPU-only tests of local runner behavior; no cuML build or GPU is needed.
set -euo pipefail
REPO=$(dirname "$(dirname "$(realpath "${BASH_SOURCE[0]}")")")
cd "${REPO}"

source /opt/conda/etc/profile.d/conda.sh
rapids-logger "Create minimal runner-test environment"
rapids-mamba-retry create --yes --name local-runner-tests --override-channels \
--channel conda-forge python=3.12 pytest packaging pyyaml cmake git
conda activate local-runner-tests

# The shared CPU workflow uploads this directory even when the script fails.
REPORT_DIR="${RAPIDS_ARTIFACTS_DIR:-${REPO}/artifacts}/local-runner-tests"
mkdir -p "${REPORT_DIR}"
export PYTEST_DISABLE_PLUGIN_AUTOLOAD=1
python -m pytest ci/tests --junitxml="${REPORT_DIR}/junit.xml"
5 changes: 5 additions & 0 deletions ci/tests/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

[pytest]
addopts = -ra

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a LOT of complexity... do we really need pytest tests on the custom pytest entrypoint that runs cuML's pytest tests?

If so I'd at least remove this file and just stick -ra in the script that runs test_pytest_entrypoint.py, to reduce the number of competing sources of configuration.

But IMO this whole ci/tests and the corresponding CI job should just be deleted.

130 changes: 130 additions & 0 deletions ci/tests/test_pytest_entrypoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

"""CPU-only subprocess tests of the real pytest argument/collection lifecycle."""

import os
from pathlib import Path
import shutil
import subprocess
import sys

import pytest

REPO = Path(__file__).resolve().parents[2]


@pytest.fixture
def repo(tmp_path):
(tmp_path / "ci").mkdir()
shutil.copy(REPO / "ci/cuml_pytest.py", tmp_path / "ci")
(tmp_path / "pyproject.toml").write_text(
'[tool.pytest.ini_options]\naddopts = "-p cuml_pytest"\n'
'pythonpath = ["ci"]\n'
)
for suite in ("tests", "tests/dask", "cuml_accel_tests"):
directory = tmp_path / "python/cuml" / suite
directory.mkdir(parents=True, exist_ok=True)
name = suite.replace("/", "_")
(directory / f"test_{name}.py").write_text(
"def test_selected(): pass\ndef test_other(): pass\n"
)
# A suite plugin must be registered during initial conftest discovery,
# not during collection after pytest's configure phase.
(tmp_path / "ci/suite_plugin.py").write_text("# suite plugin\n")
(tmp_path / "python/cuml/cuml_accel_tests/conftest.py").write_text(
"pytest_plugins = ['suite_plugin']\n"
)
return tmp_path


def run(repo, *args, cwd=None, env=None):
return subprocess.run(
[sys.executable, "-m", "pytest", *args],
cwd=cwd or repo,
env={
**os.environ,
"PYTEST_DISABLE_PLUGIN_AUTOLOAD": "1",
**(env or {}),
},
text=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)


@pytest.mark.parametrize("args", [(), ("-k", "selected"), ("-m", "not slow")])
def test_default_suite(repo, args):
result = run(repo, "--collect-only", "-q", *args)
assert result.returncode == 0, result.stdout
assert "test_tests.py::test_selected" in result.stdout
assert "test_tests_dask" not in result.stdout
assert "test_cuml_accel_tests" not in result.stdout
if args[:1] == ("-k",):
assert "::test_other" not in result.stdout


@pytest.mark.parametrize("subdir", [".", "python/cuml", "python/cuml/tests"])
def test_node_id_and_report_are_caller_relative(repo, subdir):
cwd = repo / subdir
target = os.path.relpath(repo / "python/cuml/tests/test_tests.py", cwd)
result = run(
repo, f"{target}::test_selected", "--junitxml=report.xml", cwd=cwd
)
assert result.returncode == 0, result.stdout
assert "1 passed" in result.stdout
assert (cwd / "report.xml").exists()


@pytest.mark.parametrize("suite", ["dask", "accel"])
def test_suite_defaults_and_overrides(repo, suite):
result = run(repo, f"--cuml-suite={suite}", "-k", "selected")
assert result.returncode == 0, result.stdout
assert "1 passed" in result.stdout
result = run(
repo,
f"--cuml-suite={suite}",
"python/cuml/tests/test_tests.py::test_other",
)
assert result.returncode == 0, result.stdout
assert "1 passed" in result.stdout


def test_explicit_dask_not_ignored(repo):
result = run(repo, "python/cuml/tests/dask")
assert result.returncode == 0, result.stdout
assert "2 passed" in result.stdout


@pytest.mark.parametrize(
"runner",
[
"ci/run_cuml_singlegpu_pytests.sh",
"ci/run_cuml_dask_pytests.sh",
"ci/run_cuml_singlegpu_accel_pytests.sh",
"ci/run_cuml_integration_pytests.sh",
],
)
def test_runner_preserves_arguments_and_cwd(tmp_path, runner):
# Capture the exact interpreter invocation; no GPU or upstream checkout.
executable = tmp_path / "python"
executable.write_text('#!/bin/bash\nprintf "%s\\n" "$PWD" "$@"\n')
executable.chmod(0o755)
result = subprocess.run(
[
str(REPO / runner),
"some path/test_file.py::test_one",
"-k",
"a or b",
],
cwd=tmp_path,
env={**os.environ, "PATH": f"{tmp_path}:{os.environ['PATH']}"},
text=True,
capture_output=True,
)
assert result.returncode == 0, result.stderr
lines = result.stdout.splitlines()
assert lines[0] == str(tmp_path)
assert lines[1:5] == ["-m", "pytest", "-c", str(REPO / "pyproject.toml")]
assert lines[-3:] == ["some path/test_file.py::test_one", "-k", "a or b"]
assert "." not in lines
Loading
Loading