Skip to content

Commit 2216e5b

Browse files
committed
Python: Switch to the modern approach for running unit tests
Since the release of Setuptools 41.5.0 in 2019, using "python setup.py test" to run unit tests is deprecated. A more recent change causes running "python setup.py test" to fail entirely. Hence switch to "python -m unittest". The "unittest" module was introduced before 2010.
1 parent 84fd7a8 commit 2216e5b

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

Makefile.in

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,10 @@ pythonuninstall:
244244
echo "WARNING: python doesn't support uninstall"
245245

246246
pythontest:
247-
@(dir=`pwd`; cd python; $(PYMAKE) test --basedir=$$dir) ; \
247+
@(export LD_LIBRARY_PATH="$$PWD/snmplib/.libs:$$PWD/agent/.libs:$$PWD/agent/helpers/.libs:"; \
248+
export MIBDIRS="$$PWD/mibs"; \
249+
export PYTHONPATH=$$(echo "$$PWD"/python/build/lib.*); \
250+
$(PYTHON) -m unittest python/netsnmp/tests/test.py)
248251
if test $$? != 0 ; then \
249252
exit 1 ; \
250253
fi

ci/net-snmp-run-python-tests

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
#!/bin/sh
22

3-
set -x
4-
killall snmpd
3+
set -eux
4+
if killall snmpd; then :; fi
55
export LD_LIBRARY_PATH="$PWD/snmplib/.libs:$PWD/agent/.libs:$PWD/agent/helpers/.libs:"
66
export MIBDIRS="$PWD/mibs"
77
export SNMP_PERSISTENT_DIR=/tmp/net-snmp
88
export SNMP_SNMPD_PORT=1161
9-
export PYTHONPATH="$PWD/python/netsnmp"
10-
mkdir -p "$SNMP_PERSISTENT_DIR" || exit $?
9+
for dir in "$PWD"/python/build/lib.*; do
10+
export PYTHONPATH="${dir}"
11+
break
12+
done
13+
mkdir -p "$SNMP_PERSISTENT_DIR"
1114
agent/snmpd -I-smux -r -f -Lo -c python/netsnmp/tests/snmpd.conf localhost:${SNMP_SNMPD_PORT} &
1215
pid=$!
13-
PYTHONPROG=$(sed -n 's/^S\["PYTHONPROG"\]="\(.*\)"$/\1/p' config.status) ||
14-
exit $?
15-
[ -n "$PYTHONPROG" ] || exit 1
16-
cd python || exit $?
17-
$PYTHONPROG setup.py --basedir="$PWD/.." test || exit $?
16+
PYTHONPROG=$(sed -n 's/^S\["PYTHONPROG"\]="\(.*\)"$/\1/p' config.status)
17+
[ -n "$PYTHONPROG" ]
18+
$PYTHONPROG -m unittest python/netsnmp/tests/test.py
1819
kill $pid
1920
wait

python/README

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ Installation:
7070

7171
cd net-snmp/python
7272
python setup.py build
73-
python setup.py test (requires a locally running agent w/ config provided)
73+
export LD_LIBRARY_PATH="$PWD/snmplib/.libs:$PWD/agent/.libs:$PWD/agent/helpers/.libs:"
74+
export MIBDIRS="$PWD/mibs"
75+
export PYTHONPATH="$(echo $PWD/build/lib.*)"
76+
# Requires a locally running agent w/ config provided.
77+
python -m unittest netsnmp/tests/test.py
7478
python setup.py install
7579

7680

0 commit comments

Comments
 (0)