From b1fcc6449b882f16b93fac0c05c9f18e676ae8a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Mon, 19 Apr 2021 23:16:55 +0200 Subject: [PATCH] dev-python/flask-mongoengine: Run mongodb locally for tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes: https://bugs.gentoo.org/730448 Signed-off-by: Michał Górny --- .../flask-mongoengine-1.0.0.ebuild | 41 ++++++++++++++++++- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/dev-python/flask-mongoengine/flask-mongoengine-1.0.0.ebuild b/dev-python/flask-mongoengine/flask-mongoengine-1.0.0.ebuild index 9423465341ba4..1afb666dd865c 100644 --- a/dev-python/flask-mongoengine/flask-mongoengine-1.0.0.ebuild +++ b/dev-python/flask-mongoengine/flask-mongoengine-1.0.0.ebuild @@ -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 +}