From afb4794f6f71388c8a2081d8bc1d9bd678a446ca Mon Sep 17 00:00:00 2001 From: Federico Negri Date: Thu, 8 Sep 2022 06:59:02 +0200 Subject: [PATCH 1/8] Introduce e2e pytest marker --- pyproject.toml | 3 +++ tests/jms/test_task_files.py | 2 ++ tests/jms/test_tasks.py | 3 +++ 3 files changed, 8 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 80ed15f2e..2c0876ba5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,3 +23,6 @@ log_cli = true log_cli_level = "INFO" log_cli_format = "%(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s)" log_cli_date_format = "%Y-%m-%d %H:%M:%S" +markers = [ + "e2e: marks tests as end-to-end requiring a running evaluator (deselect with '-m \"not e2e\"')", +] \ No newline at end of file diff --git a/tests/jms/test_task_files.py b/tests/jms/test_task_files.py index 8a8e41aa9..d93dd06cc 100644 --- a/tests/jms/test_task_files.py +++ b/tests/jms/test_task_files.py @@ -12,6 +12,7 @@ import unittest from examples.mapdl_motorbike_frame.project_setup import create_project +import pytest from ansys.rep.client.jms import JmsApi, ProjectApi from ansys.rep.client.jms.resource import File @@ -21,6 +22,7 @@ class TaskFilesTest(REPTestCase): + @pytest.mark.e2e def test_task_files_in_single_task_definition_project(self): num_jobs = 5 client = self.client() diff --git a/tests/jms/test_tasks.py b/tests/jms/test_tasks.py index 0e7fa9124..25ddd377b 100644 --- a/tests/jms/test_tasks.py +++ b/tests/jms/test_tasks.py @@ -12,6 +12,7 @@ import uuid from examples.mapdl_motorbike_frame.project_setup import create_project +import pytest from ansys.rep.client.jms import JmsApi, ProjectApi from ansys.rep.client.jms.resource import Job, JobDefinition, Project, TaskDefinition @@ -114,6 +115,7 @@ def test_task_integration(self): tasks = project_api.get_tasks(job_id=job.id) self.assertEqual(tasks[0].job_id, job.id) + @pytest.mark.e2e def test_job_sync(self): # create base project with 1 process step and 3 design points @@ -241,6 +243,7 @@ def wait_for_evaluation_of_job(self, project_api, job_id, max_eval_time): return job + @pytest.mark.e2e def test_sync_task_definition_snapshot(self): # verity that the process step snapshot of an evaluated task in not modified # on job:sync From 93b5a0575ee2c9f385afbc6f616383a4b8e67b8d Mon Sep 17 00:00:00 2001 From: Federico Negri Date: Thu, 8 Sep 2022 09:19:43 +0200 Subject: [PATCH 2/8] Delete new users at the end of the test --- tests/auth/test_api.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/auth/test_api.py b/tests/auth/test_api.py index 976bdb69e..de28078d5 100644 --- a/tests/auth/test_api.py +++ b/tests/auth/test_api.py @@ -90,3 +90,8 @@ def test_auth_api_exceptions(self): except_obj = e self.assertEqual(except_obj.response_code, 403) + + api.delete_user(new_user) + users = api.get_users() + usernames = [x.username for x in users] + self.assertNotIn(new_user.username, usernames) From 16449d5899422421cf318c19581255d59d7410d5 Mon Sep 17 00:00:00 2001 From: Federico Negri Date: Thu, 8 Sep 2022 09:23:37 +0200 Subject: [PATCH 3/8] Skip host.docker.internal on FS lookup --- ansys/rep/client/jms/api/project_api.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ansys/rep/client/jms/api/project_api.py b/ansys/rep/client/jms/api/project_api.py index ac6147cab..a68f81194 100644 --- a/ansys/rep/client/jms/api/project_api.py +++ b/ansys/rep/client/jms/api/project_api.py @@ -540,6 +540,19 @@ def get_fs_url(project: Project): rest_gateways = [fs for fs in project.file_storages if fs["obj_type"] == "RestGateway"] rest_gateways.sort(key=lambda fs: fs["priority"], reverse=True) + # Local deployments use "https://host.docker.internal:8443/rep/fs/api" as first + # FS Rest Gateway address and "https://localhost:8443/rep/fs/api/" only as second. + # host.docker.internal is only available from within Docker, causing the first ping + # further down to always fail, with a time penalty of 2 seconds. This is particularly + # annoying when running tests. + # Therefore, we try to detect such case and move the host.docker.internal entry + # to the bottom of the list. + docker_index = next( + (i for i, rg in enumerate(rest_gateways) if "host.docker.internal" in rg["url"]), None + ) + if docker_index is not None: + rest_gateways.append(rest_gateways.pop(docker_index)) + if not rest_gateways: raise REPError(f"Project {project.name} (id={project.id}) has no Rest Gateway defined.") From dc5006822f51c65c021c9cba206be1ada45fb269 Mon Sep 17 00:00:00 2001 From: Federico Negri Date: Thu, 8 Sep 2022 10:27:03 +0200 Subject: [PATCH 4/8] Filter pytest warnings --- pyproject.toml | 6 +++++- tests/jms/test_task_files.py | 2 +- tests/jms/test_tasks.py | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 2c0876ba5..7ec74bb07 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -24,5 +24,9 @@ log_cli_level = "INFO" log_cli_format = "%(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s)" log_cli_date_format = "%Y-%m-%d %H:%M:%S" markers = [ - "e2e: marks tests as end-to-end requiring a running evaluator (deselect with '-m \"not e2e\"')", + "requires_evaluator: marks tests as end-to-end requiring a running evaluator (deselect with '-m \"not requires_evaluator\"')", +] +filterwarnings = [ + "ignore::urllib3.exceptions.InsecureRequestWarning", + "ignore::marshmallow.warnings.RemovedInMarshmallow4Warning", ] \ No newline at end of file diff --git a/tests/jms/test_task_files.py b/tests/jms/test_task_files.py index d93dd06cc..284beaa01 100644 --- a/tests/jms/test_task_files.py +++ b/tests/jms/test_task_files.py @@ -22,7 +22,7 @@ class TaskFilesTest(REPTestCase): - @pytest.mark.e2e + @pytest.mark.requires_evaluator def test_task_files_in_single_task_definition_project(self): num_jobs = 5 client = self.client() diff --git a/tests/jms/test_tasks.py b/tests/jms/test_tasks.py index 25ddd377b..dbe6c4a7a 100644 --- a/tests/jms/test_tasks.py +++ b/tests/jms/test_tasks.py @@ -115,7 +115,7 @@ def test_task_integration(self): tasks = project_api.get_tasks(job_id=job.id) self.assertEqual(tasks[0].job_id, job.id) - @pytest.mark.e2e + @pytest.mark.requires_evaluator def test_job_sync(self): # create base project with 1 process step and 3 design points @@ -243,7 +243,7 @@ def wait_for_evaluation_of_job(self, project_api, job_id, max_eval_time): return job - @pytest.mark.e2e + @pytest.mark.requires_evaluator def test_sync_task_definition_snapshot(self): # verity that the process step snapshot of an evaluated task in not modified # on job:sync From 1408133b73da9efccd7ae9e6f19feef99ad3941a Mon Sep 17 00:00:00 2001 From: Federico Negri Date: Thu, 8 Sep 2022 10:28:03 +0200 Subject: [PATCH 5/8] Update ci --- .github/workflows/ci_cd.yml | 47 ++++++++++++++++++++++++++++++------- tox.ini | 10 ++------ 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index 684d81d6d..190be6c93 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -52,39 +52,70 @@ jobs: # fail_on_error: true # vale_flags: "--config=doc/.vale.ini" - tests: - name: Tests and coverage + quick-tests: + name: Quick tests and coverage runs-on: ${{ matrix.os }} strategy: # max 1 job at a time running against the server to make it more robust max-parallel: 1 matrix: os: [windows-latest, ubuntu-latest] - python-version: ['3.7', '3.10'] + cfg: + - {python-version: "3.7", toxenv: "py37"} + - {python-version: "3.10", toxenv: "py310"} fail-fast: false steps: - uses: actions/checkout@v3 - - name: Set up Python ${{ matrix.python-version }} + - name: Set up Python ${{ matrix.cfg.python-version }} uses: actions/setup-python@v4 with: - python-version: ${{ matrix.python-version }} + python-version: ${{ matrix.cfg.python-version }} - name: Install dependencies run: | python -m pip install --upgrade pip setuptools tox tox-gh-actions + + - name: Test with tox + run: tox -e ${{ matrix.cfg.toxenv }}-noeval-cov + env: + REP_TEST_URL: https://repkube-dev.westeurope.cloudapp.azure.com/rep + REP_TEST_USERNAME: repadmin + REP_TEST_PASSWORD: repadmin + + - name: Publish Test Report + uses: mikepenz/action-junit-report@v3 + if: always() + with: + report_paths: '**/test*.xml' + check_name: Test Report ${{ matrix.os }}:${{ matrix.cfg.python-version }} + + end-to-end-tests: + name: End-to-end tests + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ env.MAIN_PYTHON_VERSION }} + uses: actions/setup-python@v4 + with: + python-version: ${{ env.MAIN_PYTHON_VERSION }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip setuptools tox tox-gh-actions + - name: Test with tox - # Only the tox environment specified in the tox.ini gh-actions is run - run: tox + run: tox -e ${{ matrix.cfg.toxenv }}-witheval-cov env: REP_TEST_URL: https://repkube-dev.westeurope.cloudapp.azure.com/rep REP_TEST_USERNAME: repadmin REP_TEST_PASSWORD: repadmin + - name: Publish Test Report uses: mikepenz/action-junit-report@v3 if: always() with: report_paths: '**/test*.xml' - check_name: Test Report ${{ matrix.os }}:${{ matrix.python-version }} + check_name: End-to-end Test Report docs: name: Documentation diff --git a/tox.ini b/tox.ini index 603e7fb5d..d1474df5f 100644 --- a/tox.ini +++ b/tox.ini @@ -4,14 +4,6 @@ envlist = style,{py37,py38,py39,py310}{,-coverage},doc skip_missing_interpreters = true -[gh-actions] -description = The tox environment to be executed in gh-actions for a given python version -python = - 3.7: style,py37-coverage,doc - 3.8: style,py38-coverage,doc - 3.9: style,py39-coverage,doc - 3.10: style,py310-coverage,doc - [testenv] description = Checks for project unit tests and coverage (if desired) basepython = @@ -24,6 +16,8 @@ basepython = passenv = REP_TEST_* setenv = PYTHONUNBUFFERED = yes + noeval: PYTEST_MARKERS = -m "not requires_evaluator" + witheval: PYTEST_MARKERS = -m "requires_evaluator" coverage: PYTEST_EXTRA_ARGS = --cov=ansys.rep --cov-report=term --cov-report=xml --cov-report=html deps = -r{toxinidir}/requirements/requirements_tests.txt From cd4d222ee4f399a744902b252a6871240bd7738f Mon Sep 17 00:00:00 2001 From: Federico Negri Date: Thu, 8 Sep 2022 10:32:30 +0200 Subject: [PATCH 6/8] Fix --- .github/workflows/ci_cd.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index 190be6c93..c9bec9074 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -76,7 +76,7 @@ jobs: python -m pip install --upgrade pip setuptools tox tox-gh-actions - name: Test with tox - run: tox -e ${{ matrix.cfg.toxenv }}-noeval-cov + run: tox -e ${{ matrix.cfg.toxenv }}-noeval-coverage env: REP_TEST_URL: https://repkube-dev.westeurope.cloudapp.azure.com/rep REP_TEST_USERNAME: repadmin @@ -104,7 +104,7 @@ jobs: python -m pip install --upgrade pip setuptools tox tox-gh-actions - name: Test with tox - run: tox -e ${{ matrix.cfg.toxenv }}-witheval-cov + run: tox -e ${{ matrix.cfg.toxenv }}-witheval env: REP_TEST_URL: https://repkube-dev.westeurope.cloudapp.azure.com/rep REP_TEST_USERNAME: repadmin From a9c5d343b0d32849770e4df974f539d89c1d6bfd Mon Sep 17 00:00:00 2001 From: Federico Negri Date: Thu, 8 Sep 2022 12:05:19 +0200 Subject: [PATCH 7/8] Fix e2e env --- .github/workflows/ci_cd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index c9bec9074..8c7505400 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -104,7 +104,7 @@ jobs: python -m pip install --upgrade pip setuptools tox tox-gh-actions - name: Test with tox - run: tox -e ${{ matrix.cfg.toxenv }}-witheval + run: tox -e py310-witheval env: REP_TEST_URL: https://repkube-dev.westeurope.cloudapp.azure.com/rep REP_TEST_USERNAME: repadmin From 6d07c337fc7fbbc318d2155586f70e99a572f66f Mon Sep 17 00:00:00 2001 From: Federico Negri Date: Thu, 8 Sep 2022 14:07:09 +0200 Subject: [PATCH 8/8] Fix env name --- .github/workflows/ci_cd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index 8c7505400..0d16cdb35 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -104,7 +104,7 @@ jobs: python -m pip install --upgrade pip setuptools tox tox-gh-actions - name: Test with tox - run: tox -e py310-witheval + run: tox -e py37-witheval env: REP_TEST_URL: https://repkube-dev.westeurope.cloudapp.azure.com/rep REP_TEST_USERNAME: repadmin