summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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):