Skip to content

Commit ae84d5f

Browse files
authored
fix(python): Ensure reference-counting tests are skipped on PyPy (#453)
PyPy's garbage collector/object deletion is not as predictable as CPython's, so you can't be sure that when you run `gc.collect()` that all unreferenced objects will be removed, and when you `del` an object, basically nothing happens (except that future garbage collections might destroy it). I did check to make sure the deleters are actually running on pypy (using `brew install pypy3.10`) manually and added a wrapper around cibuildwheel such that one can check pypy locally when debugging one of these issues.
1 parent 7265338 commit ae84d5f

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

ci/scripts/test-python-wheels.sh

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
20+
set -e
21+
set -o pipefail
22+
23+
if [ ${VERBOSE:-0} -gt 0 ]; then
24+
set -x
25+
fi
26+
27+
SOURCE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
28+
NANOARROW_DIR="$(cd "${SOURCE_DIR}/../.." && pwd)"
29+
30+
case $# in
31+
0) export CIBW_BUILD=""
32+
;;
33+
1) export CIBW_BUILD="$1"
34+
;;
35+
*) echo "Usage:"
36+
echo " Build and test wheels locally using cibuildwheel"
37+
echo " (requires pip install cibuildwheel)"
38+
echo " $0 ...builds all wheels"
39+
echo " $0 'pp*' ...builds and tests just pypy wheels"
40+
exit 1
41+
;;
42+
esac
43+
44+
# Respect existing CIBW_TEST_REQUIRES (could be used to test all wheels
45+
# with numpy and pyarrow installed, for example)
46+
export CIBW_TEST_REQUIRES="pytest $CIBW_TEST_REQUIRES"
47+
export CIBW_TEST_COMMAND="pytest {package}/tests -vv"
48+
49+
pushd "${NANOARROW_DIR}"
50+
python -m cibuildwheel --output-dir python/dist python
51+
popd

python/tests/test_c_array.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,16 @@ def test_c_array_slice_errors():
143143

144144
def test_c_array_shallow_copy():
145145
import gc
146+
import platform
146147

147148
from nanoarrow._lib import get_pyobject_buffer_count
148149

149-
gc.collect()
150+
if platform.python_implementation() == "PyPy":
151+
pytest.skip(
152+
"Reference counting/garbage collection is non-deterministic on PyPy"
153+
)
150154

155+
gc.collect()
151156
initial_ref_count = get_pyobject_buffer_count()
152157

153158
# Create an array with children

0 commit comments

Comments
 (0)