mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2026-08-13 06:25:00 -05:00
pytest: Migrate unittest/nose 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 unittest.TestCase subclasses 2) replace unittest test controls (SkipTest, fail, etc.) 3) replace unittest assertions 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:
committed by
Alexander Bokovoy
parent
292d686c0b
commit
fec66942d4
@@ -28,8 +28,8 @@ from datetime import datetime
|
||||
import time
|
||||
import re
|
||||
import os
|
||||
|
||||
from functools import wraps
|
||||
import unittest
|
||||
from urllib.error import URLError
|
||||
|
||||
import paramiko
|
||||
@@ -102,8 +102,6 @@ def screenshot(fn):
|
||||
def screenshot_wrapper(*args, **kwargs):
|
||||
try:
|
||||
return fn(*args, **kwargs)
|
||||
except unittest.SkipTest:
|
||||
raise
|
||||
except Exception:
|
||||
self = args[0]
|
||||
name = '%s_%s_%s' % (
|
||||
@@ -166,7 +164,7 @@ class UI_driver:
|
||||
def ui_driver_setup(self, request):
|
||||
cls = request.cls
|
||||
if NO_SELENIUM:
|
||||
raise unittest.SkipTest('Selenium not installed')
|
||||
pytest.skip('Selenium not installed')
|
||||
cls.load_config()
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
@@ -195,9 +193,9 @@ class UI_driver:
|
||||
with open(path, 'r') as conf:
|
||||
cls.config = yaml.load(conf)
|
||||
except yaml.YAMLError as e:
|
||||
raise unittest.SkipTest("Invalid Web UI config.\n%s" % e)
|
||||
pytest.skip("Invalid Web UI config.\n%s" % e)
|
||||
except IOError as e:
|
||||
raise unittest.SkipTest(
|
||||
pytest.skip(
|
||||
"Can't load Web UI test config: %s" % e
|
||||
)
|
||||
else:
|
||||
@@ -236,7 +234,7 @@ class UI_driver:
|
||||
|
||||
if driver_type == 'remote':
|
||||
if 'host' not in cls.config:
|
||||
raise unittest.SkipTest('Selenium server host not configured')
|
||||
pytest.skip('Selenium server host not configured')
|
||||
host = cls.config["host"]
|
||||
|
||||
if browser == 'chrome':
|
||||
@@ -252,11 +250,11 @@ class UI_driver:
|
||||
command_executor='http://%s:%d/wd/hub' % (host, port),
|
||||
desired_capabilities=capabilities)
|
||||
except URLError as e:
|
||||
raise unittest.SkipTest(
|
||||
pytest.skip(
|
||||
'Error connecting to selenium server: %s' % e
|
||||
)
|
||||
except RuntimeError as e:
|
||||
raise unittest.SkipTest(
|
||||
pytest.skip(
|
||||
'Error while establishing webdriver: %s' % e
|
||||
)
|
||||
else:
|
||||
@@ -272,11 +270,11 @@ class UI_driver:
|
||||
ff_log_path = cls.config.get("geckodriver_log_path")
|
||||
driver = webdriver.Firefox(fp, log_path=ff_log_path)
|
||||
except URLError as e:
|
||||
raise unittest.SkipTest(
|
||||
pytest.skip(
|
||||
'Error connecting to selenium server: %s' % e
|
||||
)
|
||||
except RuntimeError as e:
|
||||
raise unittest.SkipTest(
|
||||
pytest.skip(
|
||||
'Error while establishing webdriver: %s' % e
|
||||
)
|
||||
|
||||
@@ -2019,7 +2017,7 @@ class UI_driver:
|
||||
"""
|
||||
Skip tests
|
||||
"""
|
||||
raise unittest.SkipTest(reason)
|
||||
pytest.skip(reason)
|
||||
|
||||
def assert_text(self, selector, value, parent=None):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user