fix: Add uuid to unittest.mock.MagicMock names
This allows easier debugging if unittests interfere with one another.
The release notes are empty because the changes are not relevant for users.
Here is the script I used for fixing the imports and the usage of the correct MagicMock if you want to look for logic flaws (it was run with zsh):
result=$(grep -Hrn --include \*.py --exclude="testutils.py" "MagicMock" tests/)
echo $result | cut -f1 -d':' | uniq | while read file; do
# replace unittest.mock.MagicMocks
sed -i "s/unittest.mock.MagicMock/MagicMock/g" "$file"
import_match_1=$(grep -n "from tests.testutils import" "$file")
if [[ "$import_match_1" != "" ]]; then
# add MagicMock to existing "from tests.testutils import ..."
lineno=$(echo "$import_match_1" | cut -f1 -d':')
sed -i "${lineno}s/$/, MagicMock/" "$file"
continue
fi
match=$(grep -n "import testutils" "$file")
if [[ -z "$match" ]]; then
# insert MagicMock import before last import (not after last import because
# I'm too lazy to handle imports across multiple lines)
last_lineno=$(grep -n "import.*as\|from.*import" "$file" | tail -n1 | cut -f1 -d':')
lineno=$((last_lineno - 1))
sed -i "${lineno}a\from tests.testutils import MagicMock" "$file"
else
# if there's already a "import testutils" add MagicMock import to next line
lineno=$(echo "$match" | cut -f1 -d':')
sed -i "${lineno}a\from testutils import MagicMock" "$file"
fi
done
I took inspiration from this specific unittest job: https://gitlab.com/yaook/operator/-/jobs/12777200381
Edited by Theresa Schüttig