From 98304adcaef1b427bce795293ab3aa765c7b4d21 Mon Sep 17 00:00:00 2001 From: ckunki Date: Mon, 24 Jun 2024 13:58:59 +0200 Subject: [PATCH 01/19] #295: Made notebook-tests mandatory for merge --- .github/workflows/check_ci.yaml | 44 ++++++++++++------- doc/changes/changelog.md | 2 +- .../{changes_2.1.0.md => unreleased.md} | 1 + doc/developer_guide/ci.md | 12 ++--- 4 files changed, 34 insertions(+), 25 deletions(-) rename doc/changes/{changes_2.1.0.md => unreleased.md} (95%) diff --git a/.github/workflows/check_ci.yaml b/.github/workflows/check_ci.yaml index b81d34cc..dd0e5dbd 100644 --- a/.github/workflows/check_ci.yaml +++ b/.github/workflows/check_ci.yaml @@ -1,12 +1,10 @@ name: CI Build on: - push: - branches-ignore: - - "main" + pull_request: jobs: - run_unit_tests: + run-unit-tests: runs-on: ubuntu-latest steps: @@ -18,7 +16,7 @@ jobs: uses: exasol/python-toolbox/.github/actions/python-environment@0.13.0 with: python-version: "3.10" - poetry-version: '1.8.2' + poetry-version: "1.8.2" - name: Run Unit Tests run: > @@ -28,14 +26,14 @@ jobs: --override-ini=log_cli_level=INFO test/unit - run_integration_tests: + run-integration-tests: name: Integration Tests environment: AWS_CI_TESTS runs-on: ubuntu-latest - needs: run_unit_tests + needs: run-unit-tests steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 @@ -61,8 +59,7 @@ jobs: uses: exasol/python-toolbox/.github/actions/python-environment@0.13.0 with: python-version: "3.10" - poetry-version: '1.8.2' - + poetry-version: "1.8.2" - name: Run Integration Tests run: > @@ -76,15 +73,23 @@ jobs: AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY_SECRET }} AWS_DEFAULT_REGION: ${{ secrets.AWS_REGION }} - run_notebook_tests: + approval-for-notebook-tests: + name: Run Jupyter Notebook Tests? + runs-on: ubuntu-latest + steps: + - name: Detect Running Notebook Tests + run: true + environment: + approve-test-execution + + run-notebook-tests: name: Jupyter Notebook Tests - if: "contains(github.event.head_commit.message, '[run-notebook-tests]')" environment: AWS_SAGEMAKER runs-on: ubuntu-latest - needs: run_unit_tests + needs: approval-for-notebook-tests steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 @@ -110,8 +115,7 @@ jobs: uses: exasol/python-toolbox/.github/actions/python-environment@0.13.0 with: python-version: "3.10" - poetry-version: '1.8.2' - + poetry-version: "1.8.2" - name: Run notebook tests run: > @@ -127,3 +131,11 @@ jobs: SAAS_HOST: ${{ secrets.INTEGRATION_TEAM_SAAS_STAGING_HOST }} SAAS_ACCOUNT_ID: ${{ secrets.INTEGRATION_TEAM_SAAS_STAGING_ACCOUNT_ID }} SAAS_PAT: ${{ secrets.INTEGRATION_TEAM_SAAS_STAGING_PAT }} + + gate-2: + name: Gate 2 - Allow Merge + runs-on: ubuntu-latest + needs: [ run-unit-tests, run-integration-tests, run-notebook-tests ] + steps: + - name: Branch Protection + run: true diff --git a/doc/changes/changelog.md b/doc/changes/changelog.md index 783b43d2..8b3b0ca0 100644 --- a/doc/changes/changelog.md +++ b/doc/changes/changelog.md @@ -1,6 +1,6 @@ # Changes -* [2.1.0](changes_2.1.0.md) +* [unreleased](unreleased.md) * [2.0.0](changes_2.0.0.md) * [1.0.0](changes_1.0.0.md) * [0.2.0](changes_0.2.0.md) diff --git a/doc/changes/changes_2.1.0.md b/doc/changes/unreleased.md similarity index 95% rename from doc/changes/changes_2.1.0.md rename to doc/changes/unreleased.md index 1bf4ea0a..4b63b64d 100644 --- a/doc/changes/changes_2.1.0.md +++ b/doc/changes/unreleased.md @@ -35,3 +35,4 @@ n/a * #267: Switched CodeBuildWaiter to use tenacity * #276: Started using the new ITDE Manager interface in the notebook-connector 0.2.9 * #282: Updated python version to Python 3.10 +* #295: Made notebook-tests mandatory for merge diff --git a/doc/developer_guide/ci.md b/doc/developer_guide/ci.md index 4c753814..948dc3fd 100644 --- a/doc/developer_guide/ci.md +++ b/doc/developer_guide/ci.md @@ -3,20 +3,16 @@ The project has two types of CI tests: * Unit tests and integration tests which run in a Github workflow * Special integration tests verifying the content of the Jupyter notebook files -* A system test which runs on a AWS Codebuild +* A system test which runs in a AWS Codebuild All these tests need to pass before the approval of a Github PR. The Github workflow will run on each push to a branch in the Github repository. -However, the notebook tests and the AWS Codebuild will only run after you push a commit containing a special string in the commit message, see the following sections. +However, the notebook tests and the AWS Codebuild will only run under specific conditions, e.g. manual approval or push a commit containing a special string in the commit message, see the following sections. -### Executing Notebook Tests +### Executing Jupyter Notebook Tests -Use the following git commands to execute the notebook tests: - -```shell -git commit -m "[run-notebook-tests]" --allow-empty && git push -``` +The regular CI build will ask for confirmation (aka. "review") before executing these tests, see [ETAJ developer guide](https://github.com/exasol/exasol-test-setup-abstraction-java/blob/main/doc/developer_guide/developer_guide.md#ci-build) for details. ### Executing AWS CodeBuild From 25f64aa85379f371c970c712de57982bac859a59 Mon Sep 17 00:00:00 2001 From: ckunki Date: Mon, 24 Jun 2024 14:12:40 +0200 Subject: [PATCH 02/19] Reverted renaming changes files --- doc/changes/changelog.md | 2 +- doc/changes/{unreleased.md => changes_2.1.0.md} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename doc/changes/{unreleased.md => changes_2.1.0.md} (100%) diff --git a/doc/changes/changelog.md b/doc/changes/changelog.md index 8b3b0ca0..783b43d2 100644 --- a/doc/changes/changelog.md +++ b/doc/changes/changelog.md @@ -1,6 +1,6 @@ # Changes -* [unreleased](unreleased.md) +* [2.1.0](changes_2.1.0.md) * [2.0.0](changes_2.0.0.md) * [1.0.0](changes_1.0.0.md) * [0.2.0](changes_0.2.0.md) diff --git a/doc/changes/unreleased.md b/doc/changes/changes_2.1.0.md similarity index 100% rename from doc/changes/unreleased.md rename to doc/changes/changes_2.1.0.md From e592f57c72b215975d7d654082aebb86fdf0fdb6 Mon Sep 17 00:00:00 2001 From: ckunki Date: Mon, 24 Jun 2024 14:32:21 +0200 Subject: [PATCH 03/19] Updated GitHub workflow files --- .github/workflows/check_ci.yaml | 10 ++++++++ .../workflows/check_documentation_links.yaml | 23 ------------------- ...ebook_links.yaml => check_hyperlinks.yaml} | 15 ++++++++---- .github/workflows/check_version.yaml | 21 ----------------- 4 files changed, 20 insertions(+), 49 deletions(-) delete mode 100644 .github/workflows/check_documentation_links.yaml rename .github/workflows/{check_notebook_links.yaml => check_hyperlinks.yaml} (60%) delete mode 100644 .github/workflows/check_version.yaml diff --git a/.github/workflows/check_ci.yaml b/.github/workflows/check_ci.yaml index dd0e5dbd..e22e8efd 100644 --- a/.github/workflows/check_ci.yaml +++ b/.github/workflows/check_ci.yaml @@ -18,6 +18,16 @@ jobs: python-version: "3.10" poetry-version: "1.8.2" + - name: Check Version Number + run: poetry run python3 -u "./scripts/build/check_release.py" + + - name: Link Checker + id: lychee + uses: lycheeverse/lychee-action@v1.9.0 + with: + fail: true + args: --verbose --no-progress 'doc/**/*.md' 'README.md' + - name: Run Unit Tests run: > poetry run pytest diff --git a/.github/workflows/check_documentation_links.yaml b/.github/workflows/check_documentation_links.yaml deleted file mode 100644 index 356cc4a7..00000000 --- a/.github/workflows/check_documentation_links.yaml +++ /dev/null @@ -1,23 +0,0 @@ -name: Check Documentation Links - -on: - push: - branches-ignore: - - "main" - -jobs: - check_documentation_links: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Link Checker - id: lychee - uses: lycheeverse/lychee-action@v1.9.0 - with: - fail: true - args: --verbose --no-progress 'doc/**/*.md' 'README.md' - diff --git a/.github/workflows/check_notebook_links.yaml b/.github/workflows/check_hyperlinks.yaml similarity index 60% rename from .github/workflows/check_notebook_links.yaml rename to .github/workflows/check_hyperlinks.yaml index 3282ebb8..26606b0f 100644 --- a/.github/workflows/check_notebook_links.yaml +++ b/.github/workflows/check_hyperlinks.yaml @@ -1,9 +1,7 @@ -name: Check Notebook Links +name: Check Hyperlinks on: - push: - branches-ignore: - - "main" + pull_request: jobs: check_notebook_links: @@ -19,7 +17,14 @@ jobs: python-version: "3.10" poetry-version: '1.8.2' - - name: Run build ai-lab tests + - name: Check Hyperlinks in Documentation + id: lychee + uses: lycheeverse/lychee-action@v1.9.0 + with: + fail: true + args: --verbose --no-progress 'doc/**/*.md' 'README.md' + + - name: Check Hyperlinks in Jupyter Notebooks run: > poetry run pytest --check-links exasol/ds/sandbox/runtime/ansible/roles/jupyter/files/notebook/ diff --git a/.github/workflows/check_version.yaml b/.github/workflows/check_version.yaml deleted file mode 100644 index d0b0ba3e..00000000 --- a/.github/workflows/check_version.yaml +++ /dev/null @@ -1,21 +0,0 @@ -name: Check if versions are consistent - -on: - push: - branches-ignore: - - "main" - -jobs: - check-version-numbers: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - name: Setup Python & Poetry Environment - uses: exasol/python-toolbox/.github/actions/python-environment@0.13.0 - with: - python-version: "3.10" - poetry-version: '1.8.2' - - name: Check Release - run: poetry run python3 -u "./scripts/build/check_release.py" From 00fbcb90da003821deaee833fa277d221f360cf8 Mon Sep 17 00:00:00 2001 From: ckunki Date: Mon, 24 Jun 2024 14:34:18 +0200 Subject: [PATCH 04/19] Moved shell check to check_ci.yaml --- .github/workflows/check_ci.yaml | 3 +++ .github/workflows/shellcheck.yaml | 15 --------------- 2 files changed, 3 insertions(+), 15 deletions(-) delete mode 100644 .github/workflows/shellcheck.yaml diff --git a/.github/workflows/check_ci.yaml b/.github/workflows/check_ci.yaml index e22e8efd..663d8f73 100644 --- a/.github/workflows/check_ci.yaml +++ b/.github/workflows/check_ci.yaml @@ -12,6 +12,9 @@ jobs: with: fetch-depth: 0 + - name: Run shellcheck + run: ./scripts/build/shellcheck.sh + - name: Setup Python & Poetry Environment uses: exasol/python-toolbox/.github/actions/python-environment@0.13.0 with: diff --git a/.github/workflows/shellcheck.yaml b/.github/workflows/shellcheck.yaml deleted file mode 100644 index a29939e5..00000000 --- a/.github/workflows/shellcheck.yaml +++ /dev/null @@ -1,15 +0,0 @@ -name: Check bash scripts - -on: - push: - branches: - - main - pull_request: - -jobs: - shellcheck: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Run shellcheck - run: ./scripts/build/shellcheck.sh From eac18477f5a067fe80cefa3a9f0496b4aeb998df Mon Sep 17 00:00:00 2001 From: ckunki Date: Mon, 24 Jun 2024 14:35:51 +0200 Subject: [PATCH 05/19] Renamed workflow --- .github/workflows/check_hyperlinks.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check_hyperlinks.yaml b/.github/workflows/check_hyperlinks.yaml index 26606b0f..57812f1f 100644 --- a/.github/workflows/check_hyperlinks.yaml +++ b/.github/workflows/check_hyperlinks.yaml @@ -4,13 +4,15 @@ on: pull_request: jobs: - check_notebook_links: + check-links: runs-on: ubuntu-latest steps: + - uses: actions/checkout@v4 with: fetch-depth: 0 + - name: Setup Python & Poetry Environment uses: exasol/python-toolbox/.github/actions/python-environment@0.13.0 with: @@ -27,4 +29,3 @@ jobs: - name: Check Hyperlinks in Jupyter Notebooks run: > poetry run pytest --check-links exasol/ds/sandbox/runtime/ansible/roles/jupyter/files/notebook/ - From 8bd13d82986dbe042135271351e31912f5bf9a14 Mon Sep 17 00:00:00 2001 From: ckunki Date: Mon, 24 Jun 2024 14:39:05 +0200 Subject: [PATCH 06/19] Remove hyperlinks checking from regular ci build --- .github/workflows/check_ci.yaml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.github/workflows/check_ci.yaml b/.github/workflows/check_ci.yaml index 663d8f73..abb696d6 100644 --- a/.github/workflows/check_ci.yaml +++ b/.github/workflows/check_ci.yaml @@ -24,13 +24,6 @@ jobs: - name: Check Version Number run: poetry run python3 -u "./scripts/build/check_release.py" - - name: Link Checker - id: lychee - uses: lycheeverse/lychee-action@v1.9.0 - with: - fail: true - args: --verbose --no-progress 'doc/**/*.md' 'README.md' - - name: Run Unit Tests run: > poetry run pytest From 3d4cdf9e7bf849c4a573ebcea9b6fd541f3afdc0 Mon Sep 17 00:00:00 2001 From: ckunki Date: Mon, 24 Jun 2024 15:42:15 +0200 Subject: [PATCH 07/19] Renamed Workflows --- .github/workflows/{check_ci.yaml => ci.yaml} | 3 ++- .github/workflows/{check_hyperlinks.yaml => hyperlinks.yaml} | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) rename .github/workflows/{check_ci.yaml => ci.yaml} (99%) rename .github/workflows/{check_hyperlinks.yaml => hyperlinks.yaml} (88%) diff --git a/.github/workflows/check_ci.yaml b/.github/workflows/ci.yaml similarity index 99% rename from .github/workflows/check_ci.yaml rename to .github/workflows/ci.yaml index abb696d6..dc7cf66b 100644 --- a/.github/workflows/check_ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,10 +1,11 @@ -name: CI Build +name: CI on: pull_request: jobs: run-unit-tests: + name: Run Unit Tests runs-on: ubuntu-latest steps: diff --git a/.github/workflows/check_hyperlinks.yaml b/.github/workflows/hyperlinks.yaml similarity index 88% rename from .github/workflows/check_hyperlinks.yaml rename to .github/workflows/hyperlinks.yaml index 57812f1f..9641fede 100644 --- a/.github/workflows/check_hyperlinks.yaml +++ b/.github/workflows/hyperlinks.yaml @@ -1,12 +1,12 @@ -name: Check Hyperlinks +name: Referential Integrity on: pull_request: jobs: check-links: + name: Find Broken Links in Documentation and Jupyter Notebooks runs-on: ubuntu-latest - steps: - uses: actions/checkout@v4 From f2ed3e4cd83c00d1c05855ae29e98afa21241591 Mon Sep 17 00:00:00 2001 From: ckunki Date: Mon, 24 Jun 2024 16:01:58 +0200 Subject: [PATCH 08/19] Fixed test, renamed workflow --- .github/workflows/hyperlinks.yaml | 2 +- test/integration/test_create_dss_docker_image.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/hyperlinks.yaml b/.github/workflows/hyperlinks.yaml index 9641fede..d1c7b5ec 100644 --- a/.github/workflows/hyperlinks.yaml +++ b/.github/workflows/hyperlinks.yaml @@ -1,4 +1,4 @@ -name: Referential Integrity +name: Check Hyperlinks on: pull_request: diff --git a/test/integration/test_create_dss_docker_image.py b/test/integration/test_create_dss_docker_image.py index 3ce7445d..947ed9c1 100644 --- a/test/integration/test_create_dss_docker_image.py +++ b/test/integration/test_create_dss_docker_image.py @@ -299,6 +299,7 @@ def user_and_group(ls_line: str) -> str: 'bind': notebooks_folder, 'mode': 'rw', }, }, ) as container: + wait_for(container, "entrypoint.py: Did chown -R") testees = [tmp_path, child, sub, grand_child] command = ls_command(str(tmp_path), notebooks_folder, testees) output = assert_exec_run(container, command, user=JUPYTER_USER) From daa4065ac0fc04662e109cad42668e1c0c2ed943 Mon Sep 17 00:00:00 2001 From: ckunki Date: Mon, 24 Jun 2024 16:04:01 +0200 Subject: [PATCH 09/19] Renamed workflow --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index dc7cf66b..b48c8a2e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -5,7 +5,7 @@ on: jobs: run-unit-tests: - name: Run Unit Tests + name: Unit Tests runs-on: ubuntu-latest steps: From 61f501bad67dfeaf92f546495860306d7dcacdcb Mon Sep 17 00:00:00 2001 From: ckunki Date: Tue, 25 Jun 2024 16:43:24 +0200 Subject: [PATCH 10/19] Sort notebook files before running notebook tests added log message for executing each single notebook test file --- .../test_notebooks_in_dss_docker_image.py | 47 ++++++++++++++----- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/test/notebook_test_runner/test_notebooks_in_dss_docker_image.py b/test/notebook_test_runner/test_notebooks_in_dss_docker_image.py index bd4b97e0..01b3ea7d 100644 --- a/test/notebook_test_runner/test_notebooks_in_dss_docker_image.py +++ b/test/notebook_test_runner/test_notebooks_in_dss_docker_image.py @@ -11,6 +11,7 @@ from test.docker.exec_run import exec_command from test.docker.image import image from test.docker.in_memory_build_context import InMemoryBuildContext +# from test.docker.docker_container_copy import copy_script_to_container from test.docker.container import ( container, wait_for_socket_access, @@ -65,24 +66,37 @@ def notebook_test_container(request, notebook_test_image): ) +WARNINGS = { + "DeprecationWarning": [ + "Jupyter is migrating its paths to use standard platformdirs", + "pkg_resources is deprecated as an API", + "Deprecated call to \\`pkg_resources.declare_namespace", + ] +} + + +def pytest_ini_ignoring_warnings(): + content = "[pytest]\nfilterwarnings = \n" + for category,messages in WARNINGS.items(): + for m in messages: + content += f' ignore:{m}:{category}\n' + return content + + @pytest.fixture() def notebook_test_container_with_log(notebook_test_container): - wait_for_socket_access(notebook_test_container) - logs = notebook_test_container.logs().decode("utf-8").strip() + container = notebook_test_container + wait_for_socket_access(container) + logs = container.logs().decode("utf-8").strip() print(f"Container Logs: {logs or '(empty)'}", flush=True) - yield notebook_test_container + # options = pytest_ini_ignoring_warnings() + # copy_script_to_container(options, "pytest.ini", container) + yield container def ignored_warnings(): - warnings = { - "DeprecationWarning": [ - "Jupyter is migrating its paths to use standard platformdirs", - "pkg_resources is deprecated as an API", - "Deprecated call to \\`pkg_resources.declare_namespace", - ] - } args = "" - for category, messages in warnings.items(): + for category, messages in WARNINGS.items(): for m in messages: args += f' -W "ignore:{m}:{category}"' return args @@ -92,11 +106,12 @@ def ignored_warnings(): "notebook_test_file", [ python_file.name - for python_file in TEST_RESOURCE_PATH.glob("nbtest_*.py") + for python_file in sorted(TEST_RESOURCE_PATH.glob("nbtest_*.py")) if python_file.is_file() ] ) def test_notebook(notebook_test_container_with_log, notebook_test_file): + _logger.info(f"Running notebook tests for {notebook_test_file}") container = notebook_test_container_with_log command_echo_virtual_env = 'bash -c "echo $VIRTUAL_ENV"' virtual_env = exec_command(command_echo_virtual_env, container) @@ -109,4 +124,10 @@ def test_notebook(notebook_test_container_with_log, notebook_test_file): environ["NBTEST_ACTIVE"] = "TRUE" nbtest_environ = {key: value for key, value in environ.items() if ( key.startswith("NBTEST_") or key.startswith("SAAS_"))} - exec_command(command_run_test, container, print_output=True, environment=nbtest_environ, user="jupyter") + exec_command( + command_run_test, + container, + print_output=True, + environment=nbtest_environ, + user="jupyter", + ) From 2e9ddea62676d9b98ede526a42d936e838317ae7 Mon Sep 17 00:00:00 2001 From: ckunki Date: Wed, 26 Jun 2024 09:09:07 +0200 Subject: [PATCH 11/19] #193: Ignored warnings in notebook tests --- doc/changes/changes_2.1.0.md | 3 ++- test/notebooks/pytest.ini | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/doc/changes/changes_2.1.0.md b/doc/changes/changes_2.1.0.md index 7b2af5ad..8efd576a 100644 --- a/doc/changes/changes_2.1.0.md +++ b/doc/changes/changes_2.1.0.md @@ -23,7 +23,7 @@ Version: 2.1.0 ## Bug Fixes -* #289 Fixed UI in notebooks +n/a ## Documentation @@ -36,3 +36,4 @@ Version: 2.1.0 * #276: Started using the new ITDE Manager interface in the notebook-connector 0.2.9 * #282: Updated python version to Python 3.10 * #295: Made notebook-tests mandatory for merge +* #193: Ignored warnings in notebook tests diff --git a/test/notebooks/pytest.ini b/test/notebooks/pytest.ini index be8d0936..874cd245 100644 --- a/test/notebooks/pytest.ini +++ b/test/notebooks/pytest.ini @@ -1,2 +1,6 @@ [pytest] -python_files = nbtest_*.py \ No newline at end of file +python_files = nbtest_*.py +filterwarnings = + ignore:Jupyter is migrating its paths to use standard platformdirs:DeprecationWarning + ignore:pkg_resources is deprecated as an API:DeprecationWarning + ignore:Deprecated call to \`pkg_resources.declare_namespace:DeprecationWarning From 6894044ff201273b900ddab3151707675e2b7f0e Mon Sep 17 00:00:00 2001 From: ckunki Date: Wed, 26 Jun 2024 09:28:22 +0200 Subject: [PATCH 12/19] Ignore DeprecationWarnings for luigi --- test/notebook_test_runner/test_notebooks_in_dss_docker_image.py | 2 +- test/notebooks/pytest.ini | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/test/notebook_test_runner/test_notebooks_in_dss_docker_image.py b/test/notebook_test_runner/test_notebooks_in_dss_docker_image.py index 01b3ea7d..4210970c 100644 --- a/test/notebook_test_runner/test_notebooks_in_dss_docker_image.py +++ b/test/notebook_test_runner/test_notebooks_in_dss_docker_image.py @@ -118,7 +118,7 @@ def test_notebook(notebook_test_container_with_log, notebook_test_file): command_run_test = ( f"{virtual_env}/bin/python" f" -m pytest --setup-show -s {notebook_test_file}" - f"{ignored_warnings()}" + # f"{ignored_warnings()}" ) environ = os.environ.copy() environ["NBTEST_ACTIVE"] = "TRUE" diff --git a/test/notebooks/pytest.ini b/test/notebooks/pytest.ini index 874cd245..d797e119 100644 --- a/test/notebooks/pytest.ini +++ b/test/notebooks/pytest.ini @@ -4,3 +4,4 @@ filterwarnings = ignore:Jupyter is migrating its paths to use standard platformdirs:DeprecationWarning ignore:pkg_resources is deprecated as an API:DeprecationWarning ignore:Deprecated call to \`pkg_resources.declare_namespace:DeprecationWarning + ignore::DeprecationWarning:luigi.*: From 59a154c46f1e6c0b8073f07bc13f1314ff024fed Mon Sep 17 00:00:00 2001 From: ckunki Date: Wed, 26 Jun 2024 10:58:32 +0200 Subject: [PATCH 13/19] Removed old code for ignoring warnings Additionally: Added logging options to pytest.ini for notebook tests --- .../test_notebooks_in_dss_docker_image.py | 28 ------------------- test/notebooks/pytest.ini | 3 ++ 2 files changed, 3 insertions(+), 28 deletions(-) diff --git a/test/notebook_test_runner/test_notebooks_in_dss_docker_image.py b/test/notebook_test_runner/test_notebooks_in_dss_docker_image.py index 4210970c..40fa74f3 100644 --- a/test/notebook_test_runner/test_notebooks_in_dss_docker_image.py +++ b/test/notebook_test_runner/test_notebooks_in_dss_docker_image.py @@ -66,42 +66,15 @@ def notebook_test_container(request, notebook_test_image): ) -WARNINGS = { - "DeprecationWarning": [ - "Jupyter is migrating its paths to use standard platformdirs", - "pkg_resources is deprecated as an API", - "Deprecated call to \\`pkg_resources.declare_namespace", - ] -} - - -def pytest_ini_ignoring_warnings(): - content = "[pytest]\nfilterwarnings = \n" - for category,messages in WARNINGS.items(): - for m in messages: - content += f' ignore:{m}:{category}\n' - return content - - @pytest.fixture() def notebook_test_container_with_log(notebook_test_container): container = notebook_test_container wait_for_socket_access(container) logs = container.logs().decode("utf-8").strip() print(f"Container Logs: {logs or '(empty)'}", flush=True) - # options = pytest_ini_ignoring_warnings() - # copy_script_to_container(options, "pytest.ini", container) yield container -def ignored_warnings(): - args = "" - for category, messages in WARNINGS.items(): - for m in messages: - args += f' -W "ignore:{m}:{category}"' - return args - - @pytest.mark.parametrize( "notebook_test_file", [ @@ -118,7 +91,6 @@ def test_notebook(notebook_test_container_with_log, notebook_test_file): command_run_test = ( f"{virtual_env}/bin/python" f" -m pytest --setup-show -s {notebook_test_file}" - # f"{ignored_warnings()}" ) environ = os.environ.copy() environ["NBTEST_ACTIVE"] = "TRUE" diff --git a/test/notebooks/pytest.ini b/test/notebooks/pytest.ini index d797e119..7c1493da 100644 --- a/test/notebooks/pytest.ini +++ b/test/notebooks/pytest.ini @@ -5,3 +5,6 @@ filterwarnings = ignore:pkg_resources is deprecated as an API:DeprecationWarning ignore:Deprecated call to \`pkg_resources.declare_namespace:DeprecationWarning ignore::DeprecationWarning:luigi.*: + ignore::DeprecationWarning:pkg_resources.*: +log_cli = 1 +log_cli_level = INFO From 8172d1ea696f38b76c518694db869e356fe641f8 Mon Sep 17 00:00:00 2001 From: Christoph Kuhnke Date: Wed, 26 Jun 2024 16:22:22 +0200 Subject: [PATCH 14/19] Update test/notebook_test_runner/test_notebooks_in_dss_docker_image.py Co-authored-by: Torsten Kilias --- test/notebook_test_runner/test_notebooks_in_dss_docker_image.py | 1 - 1 file changed, 1 deletion(-) diff --git a/test/notebook_test_runner/test_notebooks_in_dss_docker_image.py b/test/notebook_test_runner/test_notebooks_in_dss_docker_image.py index 40fa74f3..09e058c7 100644 --- a/test/notebook_test_runner/test_notebooks_in_dss_docker_image.py +++ b/test/notebook_test_runner/test_notebooks_in_dss_docker_image.py @@ -11,7 +11,6 @@ from test.docker.exec_run import exec_command from test.docker.image import image from test.docker.in_memory_build_context import InMemoryBuildContext -# from test.docker.docker_container_copy import copy_script_to_container from test.docker.container import ( container, wait_for_socket_access, From 243ae657023cdcd7d48d654f3160a7a1a10fe5c5 Mon Sep 17 00:00:00 2001 From: ckunki Date: Wed, 26 Jun 2024 16:27:08 +0200 Subject: [PATCH 15/19] #297: Reduced log level for transitive libraries in notebook tests --- test/notebooks/nbtest_itde.py | 2 ++ test/notebooks/notebook_test_utils.py | 26 +++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/test/notebooks/nbtest_itde.py b/test/notebooks/nbtest_itde.py index 4d45222c..cd539613 100644 --- a/test/notebooks/nbtest_itde.py +++ b/test/notebooks/nbtest_itde.py @@ -4,7 +4,9 @@ take_itde_down ) from exasol.nb_connector.connections import open_pyexasol_connection +from notebook_test_utils import set_log_level_for_libraries +set_log_level_for_libraries() def test_itde(tmp_path): store_path = tmp_path / 'tmp_config.sqlite' diff --git a/test/notebooks/notebook_test_utils.py b/test/notebooks/notebook_test_utils.py index 573a8d30..50fdde2e 100644 --- a/test/notebooks/notebook_test_utils.py +++ b/test/notebooks/notebook_test_utils.py @@ -6,6 +6,7 @@ import textwrap from contextlib import contextmanager, ExitStack from datetime import timedelta +import logging import os import pytest @@ -25,6 +26,7 @@ timestamp_name, ) +LOG = logging.getLogger(__name__) def _env(var: str) -> str: result = os.environ.get(var) @@ -113,6 +115,28 @@ def init_notebook_test(): nb_client.execute() + +# ~/git/ai-lab/test/notebooks/notebook_test_utils.py +def set_log_level_for_libraries(level=logging.WARNING): + modules = cleandoc( + """ + trailets + luigi-interface + luigi-interface.PrepareDockerNetworkForTestEnvironment + luigi-interface.SpawnTestDockerDatabase + luigi-interface.SpawnTestEnvironmentWithDockerDB + luigi-interface.WaitForTestDockerDatabase + """ + ).split() + LOG.info( + f"Setting log level to '%s' for modules\n - %s", + logging.getLevelName(level), + "\n - ".join(modules), + ) + for m in modules: + logging.getLogger(m).setLevel(level) + + @contextmanager def access_to_temp_onprem_secret_store(tmp_path: Path) -> Tuple[Path, str]: """ @@ -232,7 +256,7 @@ def uploading_hack() -> Tuple[str, str]: def pause_notebook_execution(): import time time.sleep(20) - + pause_notebook_execution() """) ) From d6629aedc62f702690592df2b65402aea43546b2 Mon Sep 17 00:00:00 2001 From: ckunki Date: Wed, 26 Jun 2024 16:27:17 +0200 Subject: [PATCH 16/19] #297: Reduced log level for transitive libraries in notebook tests --- doc/changes/changes_2.1.0.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/changes/changes_2.1.0.md b/doc/changes/changes_2.1.0.md index 8efd576a..ff7ebcd2 100644 --- a/doc/changes/changes_2.1.0.md +++ b/doc/changes/changes_2.1.0.md @@ -35,5 +35,6 @@ n/a * #267: Switched CodeBuildWaiter to use tenacity * #276: Started using the new ITDE Manager interface in the notebook-connector 0.2.9 * #282: Updated python version to Python 3.10 -* #295: Made notebook-tests mandatory for merge +* #295: Made notebook-tests mandatory for merge * #193: Ignored warnings in notebook tests +* #297: Reduced log level for transitive libraries in notebook tests From ae56cb75b50f0896fd47066ccdb193a8444d65fd Mon Sep 17 00:00:00 2001 From: ckunki Date: Wed, 26 Jun 2024 17:33:35 +0200 Subject: [PATCH 17/19] fixed import --- test/notebooks/notebook_test_utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/notebooks/notebook_test_utils.py b/test/notebooks/notebook_test_utils.py index 50fdde2e..45cea1a8 100644 --- a/test/notebooks/notebook_test_utils.py +++ b/test/notebooks/notebook_test_utils.py @@ -8,6 +8,7 @@ from datetime import timedelta import logging import os +from inspect import cleandoc import pytest import nbformat From 60839a69b226922e73423553dd35ddb5cc0dbb69 Mon Sep 17 00:00:00 2001 From: ckunki Date: Wed, 26 Jun 2024 20:25:24 +0200 Subject: [PATCH 18/19] Reduce logging in all notebooks --- test/notebooks/disabled_nbtest_cloud.py | 8 +++++++- test/notebooks/nbtest_sagemaker.py | 18 ++++++++++++------ test/notebooks/nbtest_sklearn.py | 12 +++++++++--- test/notebooks/nbtest_transformers.py | 14 ++++++++++---- test/notebooks/notebook_test_utils.py | 1 + 5 files changed, 39 insertions(+), 14 deletions(-) diff --git a/test/notebooks/disabled_nbtest_cloud.py b/test/notebooks/disabled_nbtest_cloud.py index f37dcf70..fcf564a4 100644 --- a/test/notebooks/disabled_nbtest_cloud.py +++ b/test/notebooks/disabled_nbtest_cloud.py @@ -1,5 +1,11 @@ import os -from notebook_test_utils import (access_to_temp_secret_store, notebook_runner) +from notebook_test_utils import ( + access_to_temp_secret_store, + notebook_runner, + set_log_level_for_libraries, +) + +set_log_level_for_libraries() def test_cloud_notebook(notebook_runner) -> None: diff --git a/test/notebooks/nbtest_sagemaker.py b/test/notebooks/nbtest_sagemaker.py index f1129dfc..837ebeb3 100644 --- a/test/notebooks/nbtest_sagemaker.py +++ b/test/notebooks/nbtest_sagemaker.py @@ -9,10 +9,16 @@ from exasol.nb_connector.secret_store import Secrets from exasol.nb_connector.ai_lab_config import AILabConfig as CKey, StorageBackend -from notebook_test_utils import (access_to_temp_secret_store, - access_to_temp_saas_secret_store, - run_notebook, - uploading_hack) +from notebook_test_utils import ( + access_to_temp_secret_store, + access_to_temp_saas_secret_store, + run_notebook, + uploading_hack, + set_log_level_for_libraries, +) + + +set_log_level_for_libraries() def _create_aws_s3_bucket() -> str: @@ -170,7 +176,7 @@ def continuous_job_polling(): time.sleep(30) query_result = conn.execute(sql) job_status = query_result.fetchall()[0][0] - + continuous_job_polling() """) ) @@ -186,7 +192,7 @@ def test_sagemaker(access_to_temp_secret_store, uploading_hack): bucket_name = _create_aws_s3_bucket() role_name = _create_sagemaker_role_with_policy() _store_aws_credentials(store_path, store_password, bucket_name, role_name) - + current_dir = os.getcwd() try: run_notebook('main_config.ipynb', store_file, store_password) diff --git a/test/notebooks/nbtest_sklearn.py b/test/notebooks/nbtest_sklearn.py index fb75396d..c2ce925b 100644 --- a/test/notebooks/nbtest_sklearn.py +++ b/test/notebooks/nbtest_sklearn.py @@ -2,9 +2,15 @@ import pytest from exasol.nb_connector.ai_lab_config import StorageBackend -from notebook_test_utils import (access_to_temp_secret_store, - access_to_temp_saas_secret_store, - notebook_runner) +from notebook_test_utils import ( + access_to_temp_secret_store, + access_to_temp_saas_secret_store, + notebook_runner, + set_log_level_for_libraries, +) + + +set_log_level_for_libraries() @pytest.mark.parametrize('notebook_runner', [StorageBackend.onprem, StorageBackend.saas], indirect=True) diff --git a/test/notebooks/nbtest_transformers.py b/test/notebooks/nbtest_transformers.py index 141bc194..256a0adc 100644 --- a/test/notebooks/nbtest_transformers.py +++ b/test/notebooks/nbtest_transformers.py @@ -2,10 +2,16 @@ import textwrap import pytest -from notebook_test_utils import (access_to_temp_secret_store, - access_to_temp_saas_secret_store, - notebook_runner, - uploading_hack) +from notebook_test_utils import ( + access_to_temp_secret_store, + access_to_temp_saas_secret_store, + notebook_runner, + uploading_hack, + set_log_level_for_libraries, +) + + +set_log_level_for_libraries() @pytest.mark.parametrize( diff --git a/test/notebooks/notebook_test_utils.py b/test/notebooks/notebook_test_utils.py index 45cea1a8..90530a4c 100644 --- a/test/notebooks/notebook_test_utils.py +++ b/test/notebooks/notebook_test_utils.py @@ -127,6 +127,7 @@ def set_log_level_for_libraries(level=logging.WARNING): luigi-interface.SpawnTestDockerDatabase luigi-interface.SpawnTestEnvironmentWithDockerDB luigi-interface.WaitForTestDockerDatabase + httpx """ ).split() LOG.info( From d0b970a664c27d342b54b34ee06cf2976fcec2af Mon Sep 17 00:00:00 2001 From: ckunki Date: Wed, 26 Jun 2024 20:54:32 +0200 Subject: [PATCH 19/19] fixed package name for reducing logging in traitlets --- test/notebooks/notebook_test_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/notebooks/notebook_test_utils.py b/test/notebooks/notebook_test_utils.py index 90530a4c..9a01a550 100644 --- a/test/notebooks/notebook_test_utils.py +++ b/test/notebooks/notebook_test_utils.py @@ -121,7 +121,7 @@ def init_notebook_test(): def set_log_level_for_libraries(level=logging.WARNING): modules = cleandoc( """ - trailets + traitlets luigi-interface luigi-interface.PrepareDockerNetworkForTestEnvironment luigi-interface.SpawnTestDockerDatabase