dev-python/flask-mongoengine: Run mongodb locally for tests

Closes: https://bugs.gentoo.org/730448
Signed-off-by: Michał Górny <mgorny@gentoo.org>
This commit is contained in:
Michał Górny
2021-04-19 23:16:55 +02:00
parent fa177fa30b
commit b1fcc6449b

View File

@@ -15,12 +15,14 @@ SRC_URI="
LICENSE="BSD"
SLOT="0"
KEYWORDS="amd64"
# TODO: make it spawn a local mongodb instance
RESTRICT="test"
RDEPEND=">=dev-python/flask-1.1.2[${PYTHON_USEDEP}]
>=dev-python/mongoengine-0.20[${PYTHON_USEDEP}]
>=dev-python/flask-wtf-0.14.3[${PYTHON_USEDEP}]"
BDEPEND="
test? (
dev-db/mongodb
)"
distutils_enable_sphinx docs
distutils_enable_tests pytest
@@ -34,3 +36,38 @@ python_prepare_all() {
distutils-r1_python_prepare_all
}
python_test() {
local dbpath=${TMPDIR}/mongo.db
local logpath=${TMPDIR}/mongod.log
mkdir -p "${dbpath}" || die
ebegin "Trying to start mongod on port ${DB_PORT}"
LC_ALL=C \
mongod --dbpath "${dbpath}" --nojournal \
--bind_ip 127.0.0.1 --port 27017 \
--unixSocketPrefix "${TMPDIR}" \
--logpath "${logpath}" --fork || die
sleep 2
# Now we need to check if the server actually started...
if [[ -S "${TMPDIR}"/mongodb-27017.sock ]]; then
# yay!
eend 0
else
eend 1
eerror "Unable to start mongod for tests. See the server log:"
eerror " ${logpath}"
die "Unable to start mongod for tests."
fi
local failed
nonfatal epytest || failed=1
mongod --dbpath "${dbpath}" --shutdown || die
[[ ${failed} ]] && die "Tests fail with ${EPYTHON}"
rm -rf "${dbpath}" || die
}