summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkihiro Motoki <amotoki@gmail.com>2020-04-18 08:38:36 +0900
committerAkihiro Motoki <amotoki@gmail.com>2020-04-18 22:45:16 +0000
commit8eb9b7d75f73cfbc2b5ff69cb0b8fc2fc956f3d5 (patch)
treed5b2e9fd56b8f74c0547d7742d44edc0fc44c2e6
parent8a20e253598f1987ad5398eb67d7ff4266915d07 (diff)
downloadhorizon-8eb9b7d75f73cfbc2b5ff69cb0b8fc2fc956f3d5.tar.gz
Handle case without pytest for plugin tests18.3.1
Switching the test runner to pytest in horizon assumes pytest is always installed, but horizon test helpers are used in horizon plugin tests and pytest is not used in horizon plugin tests. As a result, all horizon plugin tests are now broken. This commit considers a case where pytest does not exist. A wrapper decorator for pytest.mark.xxxx is introduced and it acts as a null decorator if pytest is not installed. Change-Id: I80736b108f5ae9a36c0e756bf386468879be3293 Closes-Bug: #1873532 (cherry picked from commit 0c96dcf293be221847f30d8e1d7a0df9d0167b92)
-rw-r--r--horizon/test/helpers.py22
-rw-r--r--openstack_dashboard/test/helpers.py5
-rw-r--r--openstack_dashboard/test/integration_tests/helpers.py6
3 files changed, 24 insertions, 9 deletions
diff --git a/horizon/test/helpers.py b/horizon/test/helpers.py
index 119b6e303..bae39b823 100644
--- a/horizon/test/helpers.py
+++ b/horizon/test/helpers.py
@@ -21,6 +21,7 @@ import copy
import logging
import os
import socket
+import sys
import time
import unittest
@@ -42,8 +43,12 @@ from django.utils.encoding import force_text
from django.contrib.staticfiles.testing \
import StaticLiveServerTestCase as LiveServerTestCase
-import pytest
-
+# horizon plugins does not require pytest, so we need to consider
+# pytest is not installed.
+try:
+ import pytest
+except ImportError:
+ pass
from horizon import middleware
@@ -69,6 +74,17 @@ except ImportError as e:
wsgi.WSGIRequest.__repr__ = lambda self: "<class 'django.http.HttpRequest'>"
+def pytest_mark(name):
+ if 'pytest' in sys.modules:
+ return getattr(pytest.mark, name)
+ else:
+ # When pytest is not installed (in case of horizon plugins),
+ # we don't need a pytest marker, so just use a null decorator.
+ def wrapper(f):
+ return f
+ return wrapper
+
+
class SessionStore(SessionBase):
"""Dict like object for simulating sessions in unittests."""
@@ -221,7 +237,7 @@ class TestCase(django_test.TestCase):
", ".join(msgs))
-@pytest.mark.selenium
+@pytest_mark('selenium')
@tag('selenium')
class SeleniumTestCase(LiveServerTestCase):
@classmethod
diff --git a/openstack_dashboard/test/helpers.py b/openstack_dashboard/test/helpers.py
index dc7ecfb97..588a5f90c 100644
--- a/openstack_dashboard/test/helpers.py
+++ b/openstack_dashboard/test/helpers.py
@@ -33,7 +33,6 @@ from django.utils import http
from openstack_auth import user
from openstack_auth import utils
-import pytest
from requests.packages.urllib3.connection import HTTPConnection
from horizon import base
@@ -472,7 +471,7 @@ class ResetImageAPIVersionMixin(object):
super(ResetImageAPIVersionMixin, self).tearDown()
-@pytest.mark.selenium
+@horizon_helpers.pytest_mark('selenium')
@tag('selenium')
class SeleniumTestCase(horizon_helpers.SeleniumTestCase):
@@ -540,7 +539,7 @@ def my_custom_sort(flavor):
# PluginTestCase as a separate test process. Hopefully this workaround has gone
# in future. For more detail, see bugs 1809983, 1866666 and
# https://review.opendev.org/#/c/627640/.
-@pytest.mark.plugin_test
+@horizon_helpers.pytest_mark('plugin_test')
@tag('plugin-test')
class PluginTestCase(TestCase):
"""Test case for testing plugin system of Horizon.
diff --git a/openstack_dashboard/test/integration_tests/helpers.py b/openstack_dashboard/test/integration_tests/helpers.py
index 98d2dfa13..273b2e163 100644
--- a/openstack_dashboard/test/integration_tests/helpers.py
+++ b/openstack_dashboard/test/integration_tests/helpers.py
@@ -23,13 +23,13 @@ import traceback
from django.test import tag
from oslo_utils import uuidutils
-import pytest
from selenium.webdriver.common import action_chains
from selenium.webdriver.common import by
from selenium.webdriver.common import keys
import testtools
import xvfbwrapper
+from horizon.test import helpers
from horizon.test import webdriver
from openstack_dashboard.test.integration_tests import config
from openstack_dashboard.test.integration_tests.pages import loginpage
@@ -103,7 +103,7 @@ class AssertsMixin(object):
return self.assertEqual(list(actual), [False] * len(actual))
-@pytest.mark.integration
+@helpers.pytest_mark('integration')
@tag('integration')
class BaseTestCase(testtools.TestCase):
@@ -307,7 +307,7 @@ class BaseTestCase(testtools.TestCase):
return html_elem.get_attribute("innerHTML").encode("utf-8")
-@pytest.mark.integration
+@helpers.pytest_mark('integration')
@tag('integration')
class TestCase(BaseTestCase, AssertsMixin):