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

@@ -27,6 +27,8 @@ import distutils.spawn
import os
import unittest
import pytest
from ipalib import api
from ipalib import errors
from ipaplatform.paths import paths
@@ -51,11 +53,12 @@ class cmdline_test(XMLRPC_test):
# some reasonable default command
command = paths.LS
@classmethod
def setup_class(cls):
@pytest.fixture(autouse=True, scope="class")
def cmdline_setup(self, request, xmlrpc_setup):
# Find the executable in $PATH
# This is neded because ipautil.run resets the PATH to
# a system default.
cls = request.cls
original_command = cls.command
if not os.path.isabs(cls.command):
cls.command = distutils.spawn.find_executable(cls.command)
@@ -65,7 +68,6 @@ class cmdline_test(XMLRPC_test):
raise AssertionError(
'Command %r not available' % original_command
)
super(cmdline_test, cls).setup_class()
if not server_available:
raise unittest.SkipTest(
'Server not available: %r' % api.env.xmlrpc_uri