From c6a1f3880172b1dd7001276677c004b24bf50ba2 Mon Sep 17 00:00:00 2001 From: Oleksandr Pavlyk Date: Tue, 27 Feb 2024 06:57:25 -0600 Subject: [PATCH] To work around an issue in pytest, run tests from empty temp dir Create empty temporary directory to run "pytest" command from to work-around an issue in pytest accessing files/directories it may not have access to during test collection. https://github.com/pytest-dev/pytest/issues/11904 --- .github/workflows/conda-package.yml | 36 +++++++++++++++++++---------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/.github/workflows/conda-package.yml b/.github/workflows/conda-package.yml index f6f2450eb7..7dc2bedae4 100644 --- a/.github/workflows/conda-package.yml +++ b/.github/workflows/conda-package.yml @@ -11,6 +11,7 @@ permissions: read-all env: PACKAGE_NAME: dpctl MODULE_NAME: dpctl + TEST_ENV_NAME: test_dpctl VER_SCRIPT1: "import json; f = open('ver.json', 'r'); j = json.load(f); f.close(); " VER_SCRIPT2: "d = j['dpctl'][0]; print('='.join((d[s] for s in ('version', 'build'))))" @@ -176,13 +177,13 @@ jobs: export CHANNELS="-c $GITHUB_WORKSPACE/channel ${{ env.CHANNELS }}" export TEST_DEPENDENCIES="pytest pytest-cov cython" export PACKAGE_VERSION=$(python -c "${VER_SCRIPT1} ${VER_SCRIPT2}") - conda create -n test_dpctl $PACKAGE_NAME=${PACKAGE_VERSION} ${TEST_DEPENDENCIES} python=${{ matrix.python }} ${CHANNELS} + conda create -n ${{ env.TEST_ENV_NAME }} $PACKAGE_NAME=${PACKAGE_VERSION} ${TEST_DEPENDENCIES} python=${{ matrix.python }} ${CHANNELS} # Test installed packages - conda list -n test_dpctl + conda list -n ${{ env.TEST_ENV_NAME }} - name: Smoke test run: | . $CONDA/etc/profile.d/conda.sh - conda activate test_dpctl + conda activate ${{ env.TEST_ENV_NAME }} python -c "import dpctl; dpctl.lsplatform(verbosity=2)" - name: Install gdb run: | @@ -191,14 +192,19 @@ jobs: - name: Run test_elementwise under gdb run: | . $CONDA/etc/profile.d/conda.sh - conda activate test_dpctl + conda activate ${{ env.TEST_ENV_NAME }} gdb --batch -ex r -ex 'info sharedlibrary' -ex 'set print elements 1000' -ex bt --args ${CONDA_PREFIX}/bin/python -m pytest -q -ra --disable-warnings --pyargs dpctl.tests.elementwise.test_trigonometric::test_trig_order -vv || true + - name: Create test temp dir + # create temporary empty folder to runs tests from + # https://github.com/pytest-dev/pytest/issues/11904 + run: mkdir -p ${GITHUB_WORSPACE}/test_tmp - name: Run tests + working-directory: ${GITHUB_WORKSPACE}/test_tmp env: SYCL_CACHE_PERSISTENT: 1 run: | . $CONDA/etc/profile.d/conda.sh - conda activate test_dpctl + conda activate ${{ env.TEST_ENV_NAME }} python -m pytest -v --pyargs $MODULE_NAME test_windows: @@ -227,7 +233,7 @@ jobs: auto-update-conda: true conda-build-version: '*' miniconda-version: 'latest' - activate-environment: dpctl_test + activate-environment: ${{ env.TEST_ENV_NAME }} python-version: ${{ matrix.python }} - name: Create conda channel with the artifact bit shell: cmd /C CALL {0} @@ -257,7 +263,7 @@ jobs: FOR /F "tokens=* USEBACKQ" %%F IN (`python -c "%SCRIPT%"`) DO ( SET PACKAGE_VERSION=%%F ) - conda install -n dpctl_test ${{ env.PACKAGE_NAME }}=%PACKAGE_VERSION% python=${{ matrix.python }} -c ${{ env.workdir }}/channel ${{ env.CHANNELS }} --only-deps --dry-run > lockfile + conda install -n ${{ env.TEST_ENV_NAME }} ${{ env.PACKAGE_NAME }}=%PACKAGE_VERSION% python=${{ matrix.python }} -c ${{ env.workdir }}/channel ${{ env.CHANNELS }} --only-deps --dry-run > lockfile - name: Display lockfile content shell: pwsh run: Get-Content -Path .\lockfile @@ -287,13 +293,13 @@ jobs: SET PACKAGE_VERSION=%%F ) SET "TEST_DEPENDENCIES=pytest pytest-cov cython" - conda install -n dpctl_test ${{ env.PACKAGE_NAME }}=%PACKAGE_VERSION% %TEST_DEPENDENCIES% python=${{ matrix.python }} -c ${{ env.workdir }}/channel ${{ env.CHANNELS }} + conda install -n ${{ env.TEST_ENV_NAME }} ${{ env.PACKAGE_NAME }}=%PACKAGE_VERSION% %TEST_DEPENDENCIES% python=${{ matrix.python }} -c ${{ env.workdir }}/channel ${{ env.CHANNELS }} - name: Report content of test environment shell: cmd /C CALL {0} run: | echo "Value of CONDA enviroment variable was: " %CONDA% echo "Value of CONDA_PREFIX enviroment variable was: " %CONDA_PREFIX% - conda info && conda list -n dpctl_test + conda info && conda list -n ${{ env.TEST_ENV_NAME }} - name: Configure Intel OpenCL CPU RT shell: pwsh run: | @@ -305,17 +311,23 @@ jobs: - name: Smoke test, step 1 shell: cmd /C CALL {0} run: >- - conda activate dpctl_test && python -c "import sys; print(sys.executable)" + conda activate ${{ env.TEST_ENV_NAME }} && python -c "import sys; print(sys.executable)" - name: Smoke test, step 2 shell: cmd /C CALL {0} run: >- - conda activate dpctl_test && python -m dpctl -f + conda activate ${{ env.TEST_ENV_NAME }} && python -m dpctl -f + - name: Create empty temporary directory to run tests from + shell: cmd /C CALL {0} + # create temporary empty folder to runs tests from + # https://github.com/pytest-dev/pytest/issues/11904 + run: mkdir "%GITHUB_WORKSPACE%\test_tmp" - name: Run tests shell: cmd /C CALL {0} env: SYCL_CACHE_PERSISTENT: 1 + working-directory: ${{ env.GITHUB_WORKSPACE }}\test_tmp run: >- - conda activate dpctl_test && python -m pytest -v -s --pyargs ${{ env.MODULE_NAME }} + conda activate ${{ env.TEST_ENV_NAME }} && python -m pytest -v -s --pyargs ${{ env.MODULE_NAME }} upload_linux: needs: test_linux