diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml index cf0906b15..f04183ddd 100644 --- a/.github/workflows/ci_cd.yml +++ b/.github/workflows/ci_cd.yml @@ -208,7 +208,7 @@ jobs: name: Embedding testing and coverage runs-on: ubuntu-latest timeout-minutes: 10 - needs: [style, revn-variations] + needs: [smoke-tests, revn-variations] container: image: ${{ needs.revn-variations.outputs.test_container }} options: --entrypoint /bin/bash @@ -278,6 +278,80 @@ jobs: include_passed: true fail_on_failure: true + embedding-scripts-tests: + name: Embedding scripts testing and coverage + runs-on: ubuntu-latest + timeout-minutes: 10 + needs: [smoke-tests, revn-variations] + container: + image: ${{ needs.revn-variations.outputs.test_container }} + options: --entrypoint /bin/bash + strategy: + fail-fast: false + matrix: + python-version: ['3.9', '3.10', '3.11', '3.12'] + + steps: + - uses: actions/checkout@v4 + - name: Set up python and pip + run: | + apt update + apt install --reinstall ca-certificates + apt install lsb-release xvfb software-properties-common -y + add-apt-repository ppa:deadsnakes/ppa -y + apt install -y python${{ matrix.python-version }} python${{ matrix.python-version }}-venv + python${{ matrix.python-version }} -m venv /env + + - name: Install dependencies + run: | + . /env/bin/activate + pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org pip setuptools + pip install --upgrade pip flit + + - name: Install packages for testing + run: | + . /env/bin/activate + pip install -e .[tests] + + - name: Embedding scripts unit testing and coverage + env: + LICENSE_SERVER: ${{ secrets.LICENSE_SERVER }} + ANSYSLMD_LICENSE_FILE: 1055@${{ secrets.LICENSE_SERVER }} + ANSYS_WORKBENCH_LOGGING_CONSOLE: 0 + ANSYS_WORKBENCH_LOGGING: 0 + ANSYS_WORKBENCH_LOGGING_FILTER_LEVEL: 2 + NUM_CORES: 1 + PYTHONUNBUFFERED: 1 + run: | + . /env/bin/activate + mechanical-env pytest -m embedding_scripts -s --junitxml test_results_embedding_scripts${{ matrix.python-version }}.xml + + - name: Upload coverage results + uses: actions/upload-artifact@v4 + if: env.MAIN_PYTHON_VERSION == matrix.python-version + with: + name: coverage-tests-embedding-scripts + path: .cov + retention-days: 7 + + - name: Upload coverage results (as .coverage) + uses: actions/upload-artifact@v4 + if: env.MAIN_PYTHON_VERSION == matrix.python-version + with: + name: coverage-file-tests-embedding-scripts + path: .coverage + retention-days: 7 + + - name: Publish Test Report + uses: mikepenz/action-junit-report@v4 + if: always() + with: + report_paths: '**/test_results*.xml' + check_name: Test Report ${{ matrix.python-version }} + detailed_summary: true + include_passed: true + fail_on_failure: true + launch-tests: name: Launch testing and coverage runs-on: public-ubuntu-latest-8-cores @@ -455,7 +529,7 @@ jobs: coverage: name: Merging coverage - needs: [remote-connect, embedding-tests, launch-tests] + needs: [remote-connect, embedding-tests, embedding-scripts-tests, launch-tests] runs-on: ubuntu-latest steps: - name: Checkout repository @@ -480,6 +554,11 @@ jobs: name: coverage-file-tests-embedding path: cov-dir/embedding + - uses: actions/download-artifact@v4 + with: + name: coverage-file-tests-embedding-scripts + path: cov-dir/embedding-scripts + - uses: actions/download-artifact@v4 with: name: coverage-file-tests-remote-session-launch @@ -539,7 +618,7 @@ jobs: package: name: Package library - needs: [smoke-tests, remote-connect, embedding-tests, doc-build] + needs: [smoke-tests, remote-connect, embedding-tests, embedding-scripts-tests, doc-build] runs-on: ubuntu-latest steps: - name: Build library source and wheel artifacts diff --git a/doc/changelog.d/662.added.md b/doc/changelog.d/662.added.md new file mode 100644 index 000000000..16d1d3b01 --- /dev/null +++ b/doc/changelog.d/662.added.md @@ -0,0 +1 @@ +Add embedding_scripts marker \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 97cee9fc3..e2087f163 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -130,6 +130,7 @@ testpaths = [ ] markers = [ "embedding: tests that embed Mechanical in the python process", + "embedding_scripts: embedding tests that use subprocess", "python_env: tests that check for an appropriate python environment", "remote_session_launch: tests that launch Mechanical and work with gRPC server inside it", "remote_session_connect: tests that connect to Mechanical and work with gRPC server inside it", diff --git a/tests/conftest.py b/tests/conftest.py index a3f157b03..f495e8042 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -79,9 +79,14 @@ def pytest_collection_modifyitems(config, items): # skip embedding tests unless the mark is specified skip_embedding = pytest.mark.skip( - reason="embedding not selected for pytest run (`pytest -m embedding`). Skip by default" + reason="""embedding not selected for pytest run + (`pytest -m embedding` or `pytest -m embedding_scripts`). Skip by default""" ) - [item.add_marker(skip_embedding) for item in items if "embedding" in item.keywords] + [ + item.add_marker(skip_embedding) + for item in items + if ("embedding" or "embedding_scripts") in item.keywords + ] # TODO - skip python_env tests unless the mark is specified. (The below doesn't work!) # skip_python_env = pytest.mark.skip( diff --git a/tests/embedding/test_app.py b/tests/embedding/test_app.py index ac05e1b5f..da79ea49b 100644 --- a/tests/embedding/test_app.py +++ b/tests/embedding/test_app.py @@ -161,7 +161,7 @@ def test_app_getters_notstale(embedded_app): assert model.Name != "b" -@pytest.mark.embedding +@pytest.mark.embedding_scripts @pytest.mark.python_env def test_warning_message(test_env, pytestconfig, run_subprocess, rootdir): """Test Python.NET warning of the embedded instance using a test-scoped Python environment.""" @@ -190,7 +190,7 @@ def test_warning_message(test_env, pytestconfig, run_subprocess, rootdir): assert warning, "UserWarning should appear in the output of the script" -@pytest.mark.embedding +@pytest.mark.embedding_scripts @pytest.mark.python_env def test_private_appdata(pytestconfig, run_subprocess, rootdir): """Test embedded instance does not save ShowTriad using a test-scoped Python environment.""" @@ -204,7 +204,7 @@ def test_private_appdata(pytestconfig, run_subprocess, rootdir): assert "ShowTriad value is True" in stdout -@pytest.mark.embedding +@pytest.mark.embedding_scripts @pytest.mark.python_env def test_normal_appdata(pytestconfig, run_subprocess, rootdir): """Test embedded instance saves ShowTriad value using a test-scoped Python environment.""" diff --git a/tests/embedding/test_logger.py b/tests/embedding/test_logger.py index 9da992c21..4a8d2f2e5 100644 --- a/tests/embedding/test_logger.py +++ b/tests/embedding/test_logger.py @@ -98,7 +98,7 @@ def _run_embedding_log_test( return stderr -@pytest.mark.embedding +@pytest.mark.embedding_scripts def test_logging_write_log_before_init(rootdir, run_subprocess, pytestconfig): """Test that an error is thrown when trying to log before initializing""" stderr = _run_embedding_log_test( @@ -107,7 +107,7 @@ def test_logging_write_log_before_init(rootdir, run_subprocess, pytestconfig): assert "Can't log to the embedding logger until Mechanical is initialized" in stderr -@pytest.mark.embedding +@pytest.mark.embedding_scripts def test_logging_write_info_after_initialize_with_error_level( rootdir, run_subprocess, pytestconfig ): @@ -119,7 +119,7 @@ def test_logging_write_info_after_initialize_with_error_level( @pytest.mark.parametrize("addin_configuration", ["Mechanical", "WorkBench"]) -@pytest.mark.embedding +@pytest.mark.embedding_scripts @pytest.mark.minimum_version(241) def test_addin_configuration(rootdir, run_subprocess, pytestconfig, addin_configuration): """Test that mechanical can start with both the Mechanical and WorkBench configuration.""" @@ -129,7 +129,7 @@ def test_addin_configuration(rootdir, run_subprocess, pytestconfig, addin_config assert f"{addin_configuration} configuration!" in stderr -@pytest.mark.embedding +@pytest.mark.embedding_scripts def test_logging_write_error_after_initialize_with_info_level( rootdir, run_subprocess, pytestconfig ): @@ -140,7 +140,7 @@ def test_logging_write_error_after_initialize_with_info_level( assert "Will no one rid me of this turbulent priest?" in stderr -@pytest.mark.embedding +@pytest.mark.embedding_scripts def test_logging_level_before_and_after_initialization(rootdir, run_subprocess, pytestconfig): """Test logging level API before and after initialization.""" stdout, stderr = _run_embedding_log_test_process(