Skip to content

Commit e149db2

Browse files
author
Ramana Radhakrishnan
authored
[RFC] Pytest environment improvements (#5421)
* [RFC] Pass pytest options globally. In many places having a global pytest flag is useful . For me with the build and test of tvm , I would like to be able to globally pass in pytest options as part of development flow or CI flows where one would like to measure other things regularly that need measurements including pytest coverage data that I would like to experiment with across the stack. This has been achieved with an additional setup-pytest-env.sh file in tests/scripts rather than putting in something in every single task test script and something I would like to avoid. This now means the -v option to pytest is superfluous. I did consider having a pytest.ini file but that doesn't allow me to pass any old environment variable in and this seems to be the compromise. * Improve other use case documentation * Rationalize pytest environment. * Remove the setting from docker/with_same_user. * Take the opportunity to migrate common PYTHONPATH and TVM_PATH into the common environment setting. * Fixup vta fsim * Be more explicit with common PYTHONPATH * Fix python path for task_python_vta_fsim.sh properly * Fix nit in documentation.
1 parent ba87604 commit e149db2

13 files changed

+66
-36
lines changed

docker/bash.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ ${DOCKER_BINARY} run --rm --pid=host\
8989
-e "CI_BUILD_GROUP=$(id -g -n)" \
9090
-e "CI_BUILD_GID=$(id -g)" \
9191
-e "PYTHONPATH=python:topi/python"\
92+
-e "CI_PYTEST_ADD_OPTIONS=$CI_PYTEST_ADD_OPTIONS" \
9293
${CUDA_ENV}\
9394
${CI_DOCKER_EXTRA_PARAMS[@]} \
9495
${DOCKER_IMAGE_NAME}\

docker/build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ ${DOCKER_BINARY} run --rm --pid=host \
162162
-e "CI_BUILD_UID=$(id -u)" \
163163
-e "CI_BUILD_GROUP=$(id -g -n)" \
164164
-e "CI_BUILD_GID=$(id -g)" \
165+
-e "CI_PYTEST_ADD_OPTIONS=$CI_PYTEST_ADD_OPTIONS" \
165166
${CUDA_ENV}\
166167
${CI_DOCKER_EXTRA_PARAMS[@]} \
167168
${DOCKER_IMG_NAME} \

docker/with_the_same_user

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ getent passwd "${CI_BUILD_UID}" || adduser --gid "${CI_BUILD_GID}" --uid "${CI_B
4141
--gecos "${CI_BUILD_USER} (generated by with_the_same_user script)" \
4242
--disabled-password --home "${CI_BUILD_HOME}" --quiet "${CI_BUILD_USER}"
4343
usermod -a -G sudo "${CI_BUILD_USER}"
44+
# This is a grotesque hack to get PYTEST_ADD_OPTS available to all task scripts.
4445
echo "${CI_BUILD_USER} ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/90-nopasswd-sudo
4546

4647
if [[ ! -z $CUDA_VISIBLE_DEVICES ]]; then

docs/contribute/pull_request.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,6 @@ If you want to run a single test:
118118
rm -rf python/tvm/*.pyc python/tvm/*/*.pyc python/tvm/*/*/*.pyc
119119
120120
TVM_FFI=ctypes python -m pytest -v tests/python/unittest/test_pass_storage_rewrite.py
121+
122+
# Additionally if you want to run a single test, for example test_all_elemwise inside a file.
123+
TVM_FFI=ctypes python -m pytest -v -k "test_all_elemwise" tests/python/frontend/tflite/test_forward.py

tests/scripts/setup-pytest-env.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
19+
set -u
20+
set -e
21+
export TVM_PATH=`pwd`
22+
export PYTHONPATH=${TVM_PATH}/python:${TVM_PATH}/topi/python
23+
export PYTEST_ADDOPTS="-v $CI_PYTEST_ADD_OPTIONS"

tests/scripts/task_python_docs.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
set -e
2020
set -u
2121

22+
source tests/scripts/setup-pytest-env.sh
2223
# cleanup old states
2324
rm -rf docs/_build
2425
mkdir -p docs/_build/html

tests/scripts/task_python_frontend.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
set -e
2020
set -u
2121

22-
export PYTHONPATH=python:topi/python
22+
source tests/scripts/setup-pytest-env.sh
2323
# to avoid openblas threading error
2424
export TVM_BIND_THREADS=0
2525
export OMP_NUM_THREADS=1
@@ -30,28 +30,28 @@ find . -type f -path "*.pyc" | xargs rm -f
3030
make cython3
3131

3232
echo "Running relay TFLite frontend test..."
33-
python3 -m pytest -v tests/python/frontend/tflite
33+
python3 -m pytest tests/python/frontend/tflite
3434

3535
echo "Running relay MXNet frontend test..."
36-
python3 -m pytest -v tests/python/frontend/mxnet
36+
python3 -m pytest tests/python/frontend/mxnet
3737

3838
echo "Running relay Keras frontend test..."
39-
python3 -m pytest -v tests/python/frontend/keras
39+
python3 -m pytest tests/python/frontend/keras
4040

4141
echo "Running relay ONNX frontend test..."
42-
python3 -m pytest -v tests/python/frontend/onnx
42+
python3 -m pytest tests/python/frontend/onnx
4343

4444
echo "Running relay CoreML frontend test..."
45-
python3 -m pytest -v tests/python/frontend/coreml
45+
python3 -m pytest tests/python/frontend/coreml
4646

4747
echo "Running relay Tensorflow frontend test..."
48-
python3 -m pytest -v tests/python/frontend/tensorflow
48+
python3 -m pytest tests/python/frontend/tensorflow
4949

5050
echo "Running relay caffe2 frontend test..."
51-
python3 -m pytest -v tests/python/frontend/caffe2
51+
python3 -m pytest tests/python/frontend/caffe2
5252

5353
echo "Running relay DarkNet frontend test..."
54-
python3 -m pytest -v tests/python/frontend/darknet
54+
python3 -m pytest tests/python/frontend/darknet
5555

5656
echo "Running relay PyTorch frontend test..."
57-
python3 -m pytest -v tests/python/frontend/pytorch
57+
python3 -m pytest tests/python/frontend/pytorch

tests/scripts/task_python_integration.sh

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
set -e
2020
set -u
2121

22-
export PYTHONPATH=`pwd`/python:`pwd`/topi/python:`pwd`/apps/extension/python
22+
source tests/scripts/setup-pytest-env.sh
23+
export PYTHONPATH=${PYTHONPATH}:${TVM_PATH}/apps/extension/python
2324
export LD_LIBRARY_PATH="build:${LD_LIBRARY_PATH:-}"
2425
export TVM_BIND_THREADS=0
2526
export TVM_NUM_THREADS=2
@@ -42,26 +43,26 @@ rm -rf lib
4243
make
4344
cd ../..
4445

45-
TVM_FFI=cython python3 -m pytest -v apps/extension/tests
46-
TVM_FFI=ctypes python3 -m pytest -v apps/extension/tests
46+
TVM_FFI=cython python3 -m pytest apps/extension/tests
47+
TVM_FFI=ctypes python3 -m pytest apps/extension/tests
4748

4849
# Test dso plugin
4950
cd apps/dso_plugin_module
5051
rm -rf lib
5152
make
5253
cd ../..
53-
TVM_FFI=cython python3 -m pytest -v apps/dso_plugin_module
54-
TVM_FFI=ctypes python3 -m pytest -v apps/dso_plugin_module
54+
TVM_FFI=cython python3 -m pytest apps/dso_plugin_module
55+
TVM_FFI=ctypes python3 -m pytest apps/dso_plugin_module
5556

5657
# Do not enable TensorFlow op
5758
# TVM_FFI=cython sh prepare_and_test_tfop_module.sh
5859
# TVM_FFI=ctypes sh prepare_and_test_tfop_module.sh
5960

60-
TVM_FFI=ctypes python3 -m pytest -v tests/python/integration
61-
TVM_FFI=ctypes python3 -m pytest -v tests/python/contrib
61+
TVM_FFI=ctypes python3 -m pytest tests/python/integration
62+
TVM_FFI=ctypes python3 -m pytest tests/python/contrib
6263

63-
TVM_FFI=ctypes python3 -m pytest -v tests/python/relay
64+
TVM_FFI=ctypes python3 -m pytest tests/python/relay
6465

6566
# Do not enable OpenGL
66-
# TVM_FFI=cython python -m pytest -v tests/webgl
67-
# TVM_FFI=ctypes python3 -m pytest -v tests/webgl
67+
# TVM_FFI=cython python -m pytest tests/webgl
68+
# TVM_FFI=ctypes python3 -m pytest tests/webgl

tests/scripts/task_python_nightly.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
set -e
2020
set -u
2121

22-
export PYTHONPATH=python:topi/python
22+
source tests/scripts/setup-pytest-env.sh
2323

2424
# Rebuild cython
2525
make cython3
2626

2727
# cleanup pycache
2828
find . -type f -path "*.pyc" | xargs rm -f
2929

30-
python3 -m pytest -v topi/tests/python/nightly
30+
python3 -m pytest topi/tests/python/nightly

tests/scripts/task_python_topi.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@
1919
set -e
2020
set -u
2121

22-
export PYTHONPATH=python:topi/python
23-
22+
source tests/scripts/setup-pytest-env.sh
2423
# Rebuild cython
2524
make cython3
2625

2726
# cleanup pycache
2827
find . -type f -path "*.pyc" | xargs rm -f
2928

30-
python3 -m pytest -v topi/tests/python
29+
python3 -m pytest topi/tests/python

0 commit comments

Comments
 (0)