pytest: Migrate xunit-style setups to Pytest fixtures

Even though Pytest supports xunit style setups, unittest and nose
tests, this support is limited and may be dropped in the future
releases. Worst of all is that the mixing of various test
frameworks results in weird conflicts and of course, is not widely
tested.

This is a part of work to remove the mixing of test idioms in the
IPA's test suite:
1) replace xunit style
2) employ the fixtures' interdependencies

Related: https://pagure.io/freeipa/issue/7989
Signed-off-by: Stanislav Levin <slev@altlinux.org>
Reviewed-By: Christian Heimes <cheimes@redhat.com>
This commit is contained in:
Stanislav Levin
2019-06-20 17:14:02 +03:00
committed by Alexander Bokovoy
parent ff547a2777
commit 292d686c0b
57 changed files with 436 additions and 420 deletions

View File

@@ -86,7 +86,8 @@ def test_ip_address(addr, words, prefixlen):
class TestCIDict:
def setup(self):
@pytest.fixture(autouse=True)
def cidict_setup(self):
self.cidict = ipautil.CIDict()
self.cidict["Key1"] = "val1"
self.cidict["key2"] = "val2"

View File

@@ -41,7 +41,8 @@ class test_keyring:
Test the kernel keyring interface
"""
def setup(self):
@pytest.fixture(autouse=True)
def keyring_setup(self):
try:
kernel_keyring.del_key(TEST_KEY)
except ValueError:

View File

@@ -17,7 +17,8 @@ class test_session_storage:
Test the session storage interface
"""
def setup(self):
@pytest.fixture(autouse=True)
def session_storage_setup(self):
# TODO: set up test user and kinit to it
# tmpdir = tempfile.mkdtemp(prefix = "tmp-")
# os.environ['KRB5CCNAME'] = 'FILE:%s/ccache' % tmpdir