From 4ce54b4dd7688f467d6428a6dae79dda56df19cd Mon Sep 17 00:00:00 2001 From: AshburnLee Date: Fri, 14 Jun 2024 07:51:51 +0000 Subject: [PATCH] version 2 --- python/test/conftest.py | 22 +++++++++++++++++ scripts/pytest-utils.sh | 7 ++---- scripts/replace_skip_calls.py | 45 ----------------------------------- scripts/test-triton.sh | 21 +++++----------- 4 files changed, 30 insertions(+), 65 deletions(-) create mode 100644 python/test/conftest.py delete mode 100644 scripts/replace_skip_calls.py diff --git a/python/test/conftest.py b/python/test/conftest.py new file mode 100644 index 0000000000..66a2b93b99 --- /dev/null +++ b/python/test/conftest.py @@ -0,0 +1,22 @@ +# content of conftest.py +import os +import pytest + +def pytest_configure(config): + if os.getenv('TEST_UNSKIP') == 'false': + pass + else: + # define a function that do nothing + def unskip(reason=None, allow_module_level=False): + pass + # save the original 'pytest.skip' to config._skip_f + config._skip_f = pytest.skip + # replace 'pytest.skip' with 'pass' call + pytest.skip = unskip + +def pytest_unconfigure(config): + if os.getenv('TEST_UNSKIP') == 'false': + pass + else: + # restore 'pytest.skip' + pytest.skip = config._skip_f diff --git a/scripts/pytest-utils.sh b/scripts/pytest-utils.sh index 39e74d4774..5de8f8374a 100644 --- a/scripts/pytest-utils.sh +++ b/scripts/pytest-utils.sh @@ -13,7 +13,7 @@ TRITON_TEST_SKIPLIST_DIR="$(cd "$TRITON_TEST_SKIPLIST_DIR" && pwd)" CURRENT_SKIPLIST_DIR="$SCRIPTS_DIR/skiplist/current" pytest() { - pytest_extra_args=("--timeout=15") # need pytest-timeout installed + pytest_extra_args=() if [[ -v TRITON_TEST_SUITE && $TRITON_TEST_REPORTS = true ]]; then mkdir -p "$TRITON_TEST_REPORTS_DIR" @@ -36,11 +36,8 @@ pytest() { sed -e '/^#/d' "$TRITON_TEST_SKIPLIST_DIR/$TRITON_TEST_SUITE.txt" > "$CURRENT_SKIPLIST_DIR/$TRITON_TEST_SUITE.txt" pytest_extra_args+=( "--deselect-from-file=$CURRENT_SKIPLIST_DIR/$TRITON_TEST_SUITE.txt" + "--select-fail-on-missing" ) - # this argument results in execution error when enable unskip test - if [ "$TEST_UNSKIP" = false ]; then - pytest_extra_args+=("--select-fail-on-missing") - fi fi python3 -u -m pytest "${pytest_extra_args[@]}" "$@" || $TRITON_TEST_IGNORE_ERRORS diff --git a/scripts/replace_skip_calls.py b/scripts/replace_skip_calls.py deleted file mode 100644 index 34bd9ff0d9..0000000000 --- a/scripts/replace_skip_calls.py +++ /dev/null @@ -1,45 +0,0 @@ -"""Replace all 'pytest.skip()' to 'pass' calls.""" -import ast -import os - -class ReplaceToPassransformer(ast.NodeTransformer): - """Replace 'pytest.skip' calls to 'pass' """ - def visit_Call(self, node: ast.Call): - if isinstance(node.func, ast.Attribute): - if node.func.attr == 'skip' and isinstance(node.func.value, ast.Name) \ - and node.func.value.id == 'pytest': - return ast.Pass() - self.generic_visit(node) - return node - -def rewrite_test_scripts(src_dir: str, dest_dir: str): - """Traverse all .py files under src_dir and do the replacement, put all under the dest_dir""" - if os.path.exists(src_dir) and os.path.isdir(src_dir): - for dirpath, sub_dirname, filename in os.walk(src_dir): - # print(f"dirpath: {dirpath}") - # print(f"sub_dirname: {sub_dirname}") - # print(f"filename: {filename}") - for filename in filename: - if filename.endswith('.py'): - file_path = os.path.join(dirpath, filename) - with open(file_path, 'r') as file: - source_code = file.read() - - tree = ast.parse(source_code) - modified_tree = ReplaceToPassransformer().visit(tree) - modified_source_code = ast.unparse(modified_tree) - - relative_path = os.path.relpath(file_path, src_dir) - target_path = os.path.join(dest_dir, relative_path) - os.makedirs(os.path.dirname(target_path), exist_ok=True) - - with open(target_path, 'w') as file: - file.write(modified_source_code) - else: - print(f"{src_dir} not exist") - -if __name__ == '__main__': - triton_dir = os.getenv('TRITON_PROJ') - src_dir = os.path.join(triton_dir, "/python/test/") if triton_dir else None - dest_dir = os.path.join(triton_dir, "/tmp/python/test/") if triton_dir else None - rewrite_test_scripts(src_dir, dest_dir) diff --git a/scripts/test-triton.sh b/scripts/test-triton.sh index fb38ed03f7..a809dc0250 100755 --- a/scripts/test-triton.sh +++ b/scripts/test-triton.sh @@ -90,7 +90,7 @@ export TRITON_PROJ=$BASE/intel-xpu-backend-for-triton export TRITON_PROJ_BUILD=$TRITON_PROJ/python/build export SCRIPTS_DIR=$(cd $(dirname "$0") && pwd) -python3 -m pip install lit pytest pytest-xdist pytest-rerunfailures pytest-select pytest-timeout setuptools==69.5.1 +python3 -m pip install lit pytest pytest-xdist pytest-rerunfailures pytest-select setuptools==69.5.1 if [ "$TRITON_TEST_WARNING_REPORTS" == true ]; then python3 -m pip install git+https://github.com/kwasd/pytest-capturewarnings-ng@v1.2.0 @@ -145,16 +145,13 @@ run_core_tests() { echo "***************************************************" echo "****** Running Triton Core tests ******" echo "***************************************************" - if [ "$TEST_UNSKIP" = true ]; then - CORE_TEST_DIR=$TRITON_PROJ/tmp/python/test/unit - else - CORE_TEST_DIR=$TRITON_PROJ/python/test/unit - fi + CORE_TEST_DIR=$TRITON_PROJ/python/test/unit if [ ! -d "${CORE_TEST_DIR}" ]; then echo "Not found '${CORE_TEST_DIR}'. Build Triton please" ; exit 3 fi cd ${CORE_TEST_DIR} + export TEST_UNSKIP TRITON_DISABLE_LINE_INFO=1 TRITON_TEST_SUITE=language \ pytest -vvv -n 8 --device xpu language/ --ignore=language/test_line_info.py --ignore=language/test_subprocess.py @@ -182,11 +179,9 @@ run_regression_tests() { echo "***************************************************" echo "****** Running Triton Regression tests ******" echo "***************************************************" - if [ "$TEST_UNSKIP" = true ]; then - REGRESSION_TEST_DIR=$TRITON_PROJ/tmp/python/test/regression - else - REGRESSION_TEST_DIR=$TRITON_PROJ/python/test/regression - fi + REGRESSION_TEST_DIR=$TRITON_PROJ/python/test/regression + export TEST_UNSKIP + if [ ! -d "${REGRESSION_TEST_DIR}" ]; then echo "Not found '${REGRESSION_TEST_DIR}'. Build Triton please" ; exit 3 fi @@ -221,10 +216,6 @@ run_tutorial_tests() { } test_triton() { - # generate dir ${TRITON_PROJ}/tmp/python/test/ - if [ "$TEST_UNSKIP" = true ]; then - python ${SCRIPTS_DIR}/replace_skip_calls.py - fi if [ "$TEST_UNIT" = true ]; then run_unit_tests fi