Skip to content

Commit

Permalink
add a general notebook test script (kubeflow#763)
Browse files Browse the repository at this point in the history
* add a general notebook test script

* fix join

* fix typo

* infer notebook name with path

* replace

* fix name

* add a log

* update comment
  • Loading branch information
k8s-ci-robot authored Mar 4, 2020
1 parent 95db89a commit c5222dd
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
8 changes: 8 additions & 0 deletions py/kubeflow/examples/notebook_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def pytest_addoption(parser):
parser.addoption(
"--repos", help="The repos to checkout; leave blank to use defaults",
type=str, default="")
parser.addoption(
"--notebook_path", help=("Path to the testing notebook file, starting from"
"the base directory of examples repository."),
type=str, default="")

@pytest.fixture
def name(request):
Expand All @@ -32,3 +36,7 @@ def image(request):
@pytest.fixture
def repos(request):
return request.config.getoption("--repos")

@pytest.fixture
def notebook_path(request):
return request.config.getoption("--notebook_path")
1 change: 1 addition & 0 deletions py/kubeflow/examples/notebook_tests/nb_test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def run_papermill_job(notebook_path, name, namespace, # pylint: disable=too-many
if os.getenv("REPO_OWNER") and os.getenv("REPO_NAME"):
# Running under prow
prow_dir = prow_artifacts.get_gcs_dir(prow_bucket)
logging.info("Prow artifacts dir: %s", prow_dir)
prow_dir = os.path.join(prow_dir, "artifacts")

if os.getenv("TEST_TARGET_NAME"):
Expand Down
35 changes: 35 additions & 0 deletions py/kubeflow/examples/notebook_tests/run_notebook_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""Runs notebook ipynb as test."""

import datetime
import logging
import os
import re
import uuid

import pytest

from kubeflow.examples.notebook_tests import nb_test_util
from kubeflow.testing import util

def test_run_notebook(record_xml_attribute, namespace, # pylint: disable=too-many-branches,too-many-statements
repos, image, notebook_path):
notebook_name = os.path.basename(
notebook_path).replace(".ipynb", "").replace("_", "-")
junit_name = "_".join(["test", notebook_name])
util.set_pytest_junit(record_xml_attribute, junit_name)

name = "-".join([notebook_name,
datetime.datetime.now().strftime("%H%M%S"),
uuid.uuid4().hex[0:3]])

util.set_pytest_junit(record_xml_attribute, junit_name)
nb_test_util.run_papermill_job(notebook_path, name, namespace, repos, image)

if __name__ == '__main__':
logging.basicConfig(level=logging.INFO,
format=('%(levelname)s|%(asctime)s'
'|%(pathname)s|%(lineno)d| %(message)s'),
datefmt='%Y-%m-%dT%H:%M:%S',
)
logging.getLogger().setLevel(logging.INFO)
pytest.main()

0 comments on commit c5222dd

Please sign in to comment.