test/sources: skip if net namespace setup fails

Try to check if we can setup the net namespace and if that fails
skip the test.
This commit is contained in:
Christian Kellner 2020-12-04 10:15:58 +01:00
parent 83aa4a29df
commit ea3dad17fc

View file

@ -57,6 +57,14 @@ def fileServer(directory):
yield
def can_setup_netns() -> bool:
try:
with netns():
return True
except: # pylint: disable=bare-except
return False
def runFileServer(barrier, directory):
class Handler(http.server.SimpleHTTPRequestHandler):
def __init__(self, request, client_address, server):
@ -68,6 +76,7 @@ def runFileServer(barrier, directory):
@unittest.skipUnless(test.TestBase.have_test_data(), "no test-data access")
@unittest.skipUnless(can_setup_netns(), "network namespace setup failed")
class TestSources(test.TestBase):
def setUp(self):
self.sources = os.path.join(self.locate_test_data(), "sources")