Skip to content

Commit

Permalink
Fix test execution on Python 3.12
Browse files Browse the repository at this point in the history
Python 3.12 deprecates setup.py and distutils. Update setup_tests.sh and
run_tests.sh to make them work again in 3.12.

We manually patch the Anki source code to not depend on distutils. This
fix was applied upstream but we test against an old Anki version so we
don't have to build Rust stuff. We should stop kicking that can down the
road at some point.

Note that tests currently fail both locally and in CI with the error
"AttributeError: 'TestWithCollection' object has no attribute 'col'".
I think this error is unrelated to this commit and I will fix it in a
subsequent commit.
  • Loading branch information
kerrickstaley committed May 13, 2024
1 parent b32c688 commit 61fc2cb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ set -e
# enter venv if needed
[[ -z "$VIRTUAL_ENV" ]] && source tests_venv/bin/activate

exec python setup.py pytest --addopts tests
exec python -m pytest tests/
10 changes: 7 additions & 3 deletions setup_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@ set -e
anki_test_revision=ed8340a4e3a2006d6285d7adf9b136c735ba2085

# install pyaudio system deps
sudo apt-get -y update && sudo apt-get install -y python-all-dev portaudio19-dev \
|| sudo pacman -S --noconfirm portaudio python-virtualenv
sudo apt-get -y update && sudo apt-get install -y python-all-dev portaudio19-dev ripgrep moreutils \
|| sudo pacman -S --noconfirm --needed portaudio python-virtualenv ripgrep moreutils

# enter venv if needed
if [[ -z "$VIRTUAL_ENV" ]]; then
rm -rf tests_venv
virtualenv -p python3 tests_venv
source tests_venv/bin/activate
fi
pip --isolated install .
pip --isolated install 'pytest>=6.0.2'

# clone Anki upstream at specific revision, install dependencies
rm -rf anki_upstream
git clone https://github.com/ankitects/anki.git anki_upstream
( cd anki_upstream
git reset --hard $anki_test_revision
pip install -r requirements.txt
pip --isolated install -r requirements.txt
# patch in commit d261d1e
rg --replace 'from shutil import which as find_executable' --passthru --no-line-number --multiline 'from distutils\.spawn import[^)]*\)' anki/mpv.py | sponge anki/mpv.py
)

0 comments on commit 61fc2cb

Please sign in to comment.