From 387b8b46b874f2b3be67226665f2fd89ed342690 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Thu, 23 Oct 2014 13:31:45 +0200 Subject: [PATCH] test_ipapython: Use functions instead of classes in test generators pytest's support for Nose-style test generators is not bulletproof; use a real function to please it. https://fedorahosted.org/freeipa/ticket/4610 Reviewed-By: Tomas Babej --- ipatests/test_ipapython/test_ipautil.py | 11 ++++++----- ipatests/test_ipapython/test_ssh.py | 11 +++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/ipatests/test_ipapython/test_ipautil.py b/ipatests/test_ipapython/test_ipautil.py index 04a43990e..c882df2cd 100644 --- a/ipatests/test_ipapython/test_ipautil.py +++ b/ipatests/test_ipapython/test_ipautil.py @@ -24,16 +24,17 @@ import nose from ipapython import ipautil -class CheckIPAddress: - def __init__(self, addr): - self.description = "Test IP address parsing and verification (%s)" % addr - def __call__(self, addr, words=None, prefixlen=None): +def make_ipaddress_checker(addr, words=None, prefixlen=None): + def check_ipaddress(): try: ip = ipautil.CheckedIPAddress(addr, match_local=False) assert ip.words == words and ip.prefixlen == prefixlen except: assert words is None and prefixlen is None + check_ipaddress.description = "Test IP address parsing and verification (%s)" % addr + return check_ipaddress + def test_ip_address(): addrs = [ @@ -66,7 +67,7 @@ def test_ip_address(): ] for addr in addrs: - yield (CheckIPAddress(addr[0]),) + addr + yield make_ipaddress_checker(*addr) class TestCIDict(object): diff --git a/ipatests/test_ipapython/test_ssh.py b/ipatests/test_ipapython/test_ssh.py index 2640af50d..db136a898 100644 --- a/ipatests/test_ipapython/test_ssh.py +++ b/ipatests/test_ipapython/test_ssh.py @@ -25,16 +25,15 @@ import nose from ipapython import ssh -class CheckPublicKey: - def __init__(self, pk): - self.description = "Test SSH public key parsing (%s)" % repr(pk) - - def __call__(self, pk, out): +def make_public_key_checker(pk, out): + def check_public_key(): try: parsed = ssh.SSHPublicKey(pk) assert parsed.openssh() == out except Exception, e: assert type(e) is out + check_public_key.description = "Test SSH public key parsing (%s)" % repr(pk) + return check_public_key def test_public_key_parsing(): b64 = 'AAAAB3NzaC1yc2EAAAADAQABAAABAQDGAX3xAeLeaJggwTqMjxNwa6XHBUAikXPGMzEpVrlLDCZtv00djsFTBi38PkgxBJVkgRWMrcBsr/35lq7P6w8KGIwA8GI48Z0qBS2NBMJ2u9WQ2hjLN6GdMlo77O0uJY3251p12pCVIS/bHRSq8kHO2No8g7KA9fGGcagPfQH+ee3t7HUkpbQkFTmbPPN++r3V8oVUk5LxbryB3UIIVzNmcSIn3JrXynlvui4MixvrtX6zx+O/bBo68o8/eZD26QrahVbA09fivrn/4h3TM019Eu/c2jOdckfU3cHUV/3Tno5d6JicibyaoDDK7S/yjdn5jhaz8MSEayQvFkZkiF0L' @@ -73,4 +72,4 @@ def test_public_key_parsing(): ] for pk in pks: - yield (CheckPublicKey(pk[0]),) + pk + yield make_public_key_checker(*pk)