commit:     b1fcc6449b882f16b93fac0c05c9f18e676ae8a0
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Mon Apr 19 21:16:55 2021 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Mon Apr 19 21:22:53 2021 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=b1fcc644

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

Closes: https://bugs.gentoo.org/730448
Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>

 .../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 9423465341b..1afb666dd86 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
+}

Reply via email to