@@ -17,55 +17,49 @@ set -e
1717# this environment variable allows special tests to run
1818export PL_RUNNING_SPECIAL_TESTS=1
1919# python arguments
20- defaults=' -m coverage run --source pytorch_lightning --append -m pytest --durations=0 -- capture=no --disable-warnings '
20+ defaults=' -m coverage run --source pytorch_lightning --append -m pytest --capture=no'
2121
22- # find tests marked as `@RunIf(special=True)`
23- grep_output=$( grep --recursive --line-number --word-regexp ' tests' ' benchmarks' --regexp ' special=True' )
24- # file paths
25- files=$( echo " $grep_output " | cut -f1 -d:)
26- files_arr=($files )
27- # line numbers
28- linenos=$( echo " $grep_output " | cut -f2 -d:)
29- linenos_arr=($linenos )
22+ # find tests marked as `@RunIf(special=True)`. done manually instead of with pytest because it is faster
23+ grep_output=$( grep --recursive --word-regexp ' tests' ' benchmarks' --regexp ' special=True' --include ' *.py' --exclude ' tests/conftest.py' )
24+
25+ # file paths, remove duplicates
26+ files=$( echo " $grep_output " | cut -f1 -d: | sort | uniq)
27+
28+ # get the list of parametrizations. we need to call them separately. the last two lines are removed.
29+ # note: if there's a syntax error, this will fail with some garbled output
30+ if [[ " $OSTYPE " == " darwin" * ]]; then
31+ parametrizations=$( pytest $files --collect-only --quiet | tail -r | sed -e ' 1,3d' | tail -r)
32+ else
33+ parametrizations=$( pytest $files --collect-only --quiet | head -n -2)
34+ fi
35+ parametrizations_arr=($parametrizations )
3036
3137# tests to skip - space separated
32- blocklist=' test_pytorch_profiler_nested_emit_nvtx'
38+ blocklist=' tests/profiler/test_profiler.py:: test_pytorch_profiler_nested_emit_nvtx'
3339report=' '
3440
35- for i in " ${! files_arr[@]} " ; do
36- file=${files_arr[$i]}
37- lineno=${linenos_arr[$i]}
38-
39- # get code from `@RunIf(special=True)` line to EOF
40- test_code=$( tail -n +" $lineno " " $file " )
41+ for i in " ${! parametrizations_arr[@]} " ; do
42+ parametrization=${parametrizations_arr[$i]}
4143
42- # read line by line
43- while read -r line; do
44- # if it's a test
45- if [[ $line == def\ test_* ]]; then
46- # get the name
47- test_name=$( echo $line | cut -c 5- | cut -f1 -d\( )
44+ # check blocklist
45+ if echo $blocklist | grep -F " ${parametrization} " ; then
46+ report+=" Skipped\t$parametrization \n"
47+ continue
48+ fi
4849
49- # check blocklist
50- if echo $blocklist | grep --word-regexp " $test_name " > /dev/null; then
51- report+=" Skipped\t$file :$lineno ::$test_name \n"
52- break
53- fi
50+ # SPECIAL_PATTERN allows filtering the tests to run when debugging.
51+ # use as `SPECIAL_PATTERN="foo_bar" ./special_tests.sh` to run only those
52+ # test with `foo_bar` in their name
53+ if [[ $parametrization != * $SPECIAL_PATTERN * ]]; then
54+ report+=" Skipped\t$parametrization \n"
55+ continue
56+ fi
5457
55- # SPECIAL_PATTERN allows filtering the tests to run when debugging.
56- # use as `SPECIAL_PATTERN="foo_bar" ./special_tests.sh` to run only those
57- # test with `foo_bar` in their name
58- if [[ $line != * $SPECIAL_PATTERN * ]]; then
59- report+=" Skipped\t$file :$lineno ::$test_name \n"
60- break
61- fi
58+ # run the test
59+ echo " Running ${parametrization} "
60+ python ${defaults} " ${parametrization} "
6261
63- # run the test
64- report+=" Ran\t$file :$lineno ::$test_name \n"
65- python ${defaults} " ${file} ::${test_name} "
66- break
67- fi
68- done < <( echo " $test_code " )
62+ report+=" Ran\t$parametrization \n"
6963done
7064
7165if nvcc --version; then
0 commit comments