Convert skipping memcached test to pytest way
@@ -395,8 +395,11 @@ class SessionTest(helper.CPWebCase):
t.join()
+def is_memcached_available():
try:
importlib.import_module('memcache')
+ except ImportError:
+ return False
host, port = '127.0.0.1', 11211
for res in socket.getaddrinfo(host, port, socket.AF_UNSPEC,
@@ -410,18 +413,15 @@ try:
s.settimeout(1.0)
s.connect((host, port))
s.close()
+ return True
except socket.error:
if s:
s.close()
- raise
- break
-except (ImportError, socket.error):
- class MemcachedSessionTest(helper.CPWebCase):
- setup_server = staticmethod(setup_server)
- def test(self):
- return self.skip('memcached not reachable ')
-else:
+ return False
+
+
+@pytest.mark.skipif(is_memcached_available(), 'memcached not reachable')
class MemcachedSessionTest(helper.CPWebCase):
setup_server = staticmethod(setup_server)
