[PATCH 2 of 2 logilab-database] Add support for autopkgtest

Jérémy Bobbio jeremy.bobbio at irq7.fr
Tue Jun 4 18:47:04 CEST 2019


# HG changeset patch
# User Jérémy Bobbio <jeremy.bobbio at irq7.fr>
# Date 1559235765 -7200
#      Thu May 30 19:02:45 2019 +0200
# Node ID 0b269e90e26a98ab919bfecb021305840306b9da
# Parent  9f4d9b51e41c74db2d635d6eae67855836c3e6b2
Add support for autopkgtest

In order to get the tests in the source Debian package we need
to ship them in the Python package. That's why we turn the
'test' directory into a Python package and remove the explicit
ignore from `setup.py`.

The tests themselves will install PostgreSQL and MariaDB. They
are thus marked `isolation-container` and need at least the
the lxc autopkgtest runner to be started.

diff -r 9f4d9b51e41c -r 0b269e90e26a debian/changelog
--- a/debian/changelog	Mon Jun 03 20:27:29 2019 +0200
+++ b/debian/changelog	Thu May 30 19:02:45 2019 +0200
@@ -11,6 +11,8 @@
     - Update Standards-Version to 4.3.0.
   * Disable running tests at build time: they require running databases
     to be meaningful.
+  * Add support for autopkgtest. The test starts databases and run the
+    test suite against the installed package.
 
  -- Jérémy Bobbio <jeremy.bobbio at irq7.fr>  Wed, 29 May 2019 16:24:07 +0200
 
diff -r 9f4d9b51e41c -r 0b269e90e26a debian/source/options
--- a/debian/source/options	Mon Jun 03 20:27:29 2019 +0200
+++ b/debian/source/options	Thu May 30 19:02:45 2019 +0200
@@ -1,1 +1,1 @@
-extend-diff-ignore = "^(.hg(/|ignore$|tags$)|[^/]*\.spec$|tox.ini$|test/)"
+extend-diff-ignore = "^(.hg(/|ignore$|tags$)|[^/]*\.spec$|tox.ini$)"
diff -r 9f4d9b51e41c -r 0b269e90e26a debian/tests/control
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/debian/tests/control	Thu May 30 19:02:45 2019 +0200
@@ -0,0 +1,6 @@
+Tests: unittest
+Depends:
+ @, @builddeps@,
+ postgresql,
+ python-mysqldb, python3-mysqldb, mariadb-server
+Restrictions: allow-stderr, isolation-container
diff -r 9f4d9b51e41c -r 0b269e90e26a debian/tests/unittest
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/debian/tests/unittest	Thu May 30 19:02:45 2019 +0200
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+set -e
+set -x
+
+### Setup PostgreSQL
+
+# Test uses getlogin() to determine username connecting to PostgreSQL
+# So we need to disable any authentication and create the given user
+sed -i 's/peer$/trust/' /etc/postgresql/*/main/pg_hba.conf
+service postgresql restart || service postgresql start
+trap 'service postgresql stop' EXIT
+psql -c "CREATE USER nobody PASSWORD 'nobody'" -U postgres
+psql -c "GRANT ALL ON DATABASE template1 TO nobody" -U postgres
+
+### Setup tests
+
+cp -r test "$AUTOPKGTEST_TMP"
+
+### Run tests
+
+for py in $(pyversions -r 2>/dev/null) $(py3versions -r 2>/dev/null); do
+	cd "$AUTOPKGTEST_TMP"
+	echo "Testing with $py:"
+	su nobody --preserve-environment --shell /bin/sh \
+		-c "$py -m unittest discover -s test -p 'unittest_*.py' -v"
+done
diff -r 9f4d9b51e41c -r 0b269e90e26a setup.py
--- a/setup.py	Mon Jun 03 20:27:29 2019 +0200
+++ b/setup.py	Thu May 30 19:02:45 2019 +0200
@@ -46,7 +46,7 @@
     license=pkginfo['license'],
     # See https://pypi.python.org/pypi?%3Aaction=list_classifiers
     classifiers=pkginfo['classifiers'],
-    packages=find_packages(exclude=['contrib', 'docs', 'test*']),
+    packages=find_packages(exclude=['contrib', 'docs']),
     namespace_packages=[pkginfo['subpackage_of']],
     install_requires=pkginfo['install_requires'],
     tests_require=pkginfo['tests_require'],


More information about the cubicweb-devel mailing list