Skip to content

Commit

Permalink
To work around an issue in pytest, run tests from empty temp dir
Browse files Browse the repository at this point in the history
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.

pytest-dev/pytest#11904
  • Loading branch information
oleksandr-pavlyk committed Feb 27, 2024
1 parent be6bced commit c6a1f38
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions .github/workflows/conda-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'))))"

Expand Down Expand Up @@ -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: |
Expand All @@ -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:
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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: |
Expand All @@ -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
Expand Down

0 comments on commit c6a1f38

Please sign in to comment.