Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Configure driver to support GPU tests #138

Merged
merged 6 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions driver/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
def pytest_addoption(parser: Parser):
"""Add pytest options.

* Add a `--proxy` option that enables setting `http_proxy`, `https_proxy` and
`no_proxy` environment variables.
* Add a `--filter` option to (de)select test cases based on their name (see also
https://docs.pytest.org/en/7.4.x/reference/reference.html#command-line-flags)
* Add an `--include-gpu-tests` flag to include the tests under the `gpu` directory
in the executed tests.
"""
parser.addoption(
"--proxy",
Expand All @@ -29,3 +33,9 @@ def pytest_addoption(parser: Parser):
" any test that doesn't contain 'kserve' in its name. Essentially, the option simulates"
" the behaviour of running `pytest -k '<filter>'` directly on the test suite.",
)
parser.addoption(
"--include-gpu-tests",
action="store_true",
help="Defines whether to include the tests under the `gpu` directory in the executed tests."
"By default, it is set to False.",
)
15 changes: 13 additions & 2 deletions driver/test_kubeflow_workloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ def pytest_filter(request):
return f"-k '{filter}'" if filter else ""


@pytest.fixture(scope="session")
def include_gpu_tests(request):
"""Retrieve the `--include-gpu-tests` flag from Pytest invocation."""
return True if request.config.getoption("--include-gpu-tests") else False
NohaIhab marked this conversation as resolved.
Show resolved Hide resolved


@pytest.fixture(scope="session")
def tests_checked_out_commit(request):
"""Retrieve active git commit."""
Expand All @@ -73,9 +79,14 @@ def tests_checked_out_commit(request):


@pytest.fixture(scope="session")
def pytest_cmd(pytest_filter):
def pytest_cmd(pytest_filter, include_gpu_tests):
"""Format the Pytest command."""
return f"{PYTEST_CMD_BASE} {pytest_filter}" if pytest_filter else PYTEST_CMD_BASE
cmd = PYTEST_CMD_BASE
if pytest_filter:
cmd += f" {pytest_filter}"
if include_gpu_tests:
cmd += " --include-gpu-tests"
return cmd


@pytest.fixture(scope="module")
Expand Down
23 changes: 23 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.

import os

from _pytest.config.argparsing import Parser


def pytest_addoption(parser: Parser):
"""Add pytest options.
* Add an `--include-gpu-tests` flag to include the tests under the `gpu` directory
in the executed tests.
"""
parser.addoption(
"--include-gpu-tests",
action="store_true",
help="Defines whether to include tests under the `gpu` directory in the executed tests."
"By default, it is set to False.",
)


def pytest_configure(config):
os.environ["include_gpu_tests"] = str(config.getoption("--include-gpu-tests"))
Empty file.
8 changes: 6 additions & 2 deletions tests/test_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
save_notebook,
)

EXAMPLES_DIR = "notebooks"
NOTEBOOKS = discover_notebooks(EXAMPLES_DIR)
EXAMPLES_DIR = {"cpu": "notebooks/cpu", "gpu": "notebooks/gpu"}
INCLUDE_GPU_TESTS = os.getenv("include_gpu_tests").lower() == "true"

NOTEBOOKS = discover_notebooks(EXAMPLES_DIR["cpu"])
if INCLUDE_GPU_TESTS:
NOTEBOOKS.update(discover_notebooks(EXAMPLES_DIR["gpu"]))
NohaIhab marked this conversation as resolved.
Show resolved Hide resolved

log = logging.getLogger(__name__)

Expand Down