Skip to content
Snippets Groups Projects
Commit 7809eb58 authored by anarcat's avatar anarcat
Browse files

try to establish a more standard way to disable network tests

parent c3dd521b
No related branches found
No related tags found
No related merge requests found
...@@ -6,7 +6,8 @@ ...@@ -6,7 +6,8 @@
# This has to be exported to make some magic below work. # This has to be exported to make some magic below work.
export DH_OPTIONS export DH_OPTIONS
export UNITTEST_NO_NETWORK=1 # disable network tests in Debian package build
export PYTEST_USENETWORK=no
%: %:
dh $@ --with=python2,sphinxdoc --buildsystem=pybuild dh $@ --with=python2,sphinxdoc --buildsystem=pybuild
......
...@@ -33,8 +33,48 @@ from test_lib import TestTimeLimit, AlarmException, find_test_file ...@@ -33,8 +33,48 @@ from test_lib import TestTimeLimit, AlarmException, find_test_file
import test_ui import test_ui
@unittest.skipIf('UNITTEST_NO_NETWORK' in os.environ, 'network tests disabled') def skipUnlessNetwork():
"""add a knob to disable network tests
to disable network tests, use PYTEST_USENETWORK=no. by default, it
is assumed there is network access.
this is mainly to deal with Debian packages that are built in
network-less chroots. unfortunately, there is no standard
environment in dpkg-buildpackage or ./debian/rules binary that we
can rely on to disable tests, so we revert to a custom variable
that can hopefully make it up to the pybuild toolchain
I looked at DEB_BUILD_OPTIONS=network, but that is not standard
and only mentionned once here:
https://lists.debian.org/debian-devel/2009/09/msg00992.html
DEB_BUILD_OPTIONS is also not set by default, so it's not a good
way to detect Debian package builds
pbuilder uses USENETWORK=no/yes, schroot uses UNSHARE_NET, but
those are not standard either, see:
https://github.com/spotify/dh-virtualenv/issues/77
https://github.com/codelibre-net/schroot/blob/2e3d015a759d2b5106e851af34c8d5974d84f18e/lib/schroot/chroot/facet/unshare.cc
"""
# by default, we run network tests
skip = False
reason = ''
if 'PYTEST_USENETWORK' in os.environ:
skip = 'no' in os.environ.get('PYTEST_USENETWORK', '')
reason = 'PYTEST_USENETWORK=no specified in environment'
if skip:
return unittest.skip('network tests disabled (%s)' % reason)
else:
return lambda func: func
@skipUnlessNetwork()
class TestGpgNetwork(TestTimeLimit): class TestGpgNetwork(TestTimeLimit):
"""Separate test cases for functions that hit the network """Separate test cases for functions that hit the network
each test needs to run under a specific timeout so we don't wait on each test needs to run under a specific timeout so we don't wait on
...@@ -67,7 +107,7 @@ the network forever""" ...@@ -67,7 +107,7 @@ the network forever"""
del self.gpg del self.gpg
@unittest.skipIf('UNITTEST_NO_NETWORK' in os.environ, 'network tests disabled') @skipUnlessNetwork()
class KeyserverTests(test_ui.BaseTestCase): class KeyserverTests(test_ui.BaseTestCase):
args = ['--keyserver', 'pool.sks-keyservers.net'] args = ['--keyserver', 'pool.sks-keyservers.net']
pattern = '7B75921E' pattern = '7B75921E'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment