Added test runner option to skip Selenium tests (#19854).
This commit is contained in:
parent
687d2e967d
commit
1cd2f51eb4
|
@ -1,3 +1,5 @@
|
||||||
|
import os
|
||||||
|
|
||||||
from django.test import LiveServerTestCase
|
from django.test import LiveServerTestCase
|
||||||
from django.utils.module_loading import import_by_path
|
from django.utils.module_loading import import_by_path
|
||||||
from django.utils.unittest import SkipTest
|
from django.utils.unittest import SkipTest
|
||||||
|
@ -8,6 +10,8 @@ class AdminSeleniumWebDriverTestCase(LiveServerTestCase):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
|
if os.environ.get('DJANGO_SKIP_SELENIUM_TESTS', False):
|
||||||
|
raise SkipTest('Selenium tests skipped by explicit request')
|
||||||
try:
|
try:
|
||||||
cls.selenium = import_by_path(cls.webdriver_class)()
|
cls.selenium = import_by_path(cls.webdriver_class)()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
@ -136,6 +136,15 @@ Then, run the tests normally, for example:
|
||||||
|
|
||||||
./runtests.py --settings=test_sqlite admin_inlines
|
./runtests.py --settings=test_sqlite admin_inlines
|
||||||
|
|
||||||
|
If you have Selenium installed but for some reason don't want to run these tests
|
||||||
|
(for example to speed up the test suite), use the ``--skip-selenium`` option
|
||||||
|
of the test runner.
|
||||||
|
|
||||||
|
.. code-block:: bash
|
||||||
|
|
||||||
|
./runtests.py --settings=test_sqlite --skip-selenium admin_inlines
|
||||||
|
|
||||||
|
|
||||||
.. _running-unit-tests-dependencies:
|
.. _running-unit-tests-dependencies:
|
||||||
|
|
||||||
Running all the tests
|
Running all the tests
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
import gettext
|
import gettext
|
||||||
|
import os
|
||||||
from os import path
|
from os import path
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
@ -176,6 +177,10 @@ class JsI18NTestsMultiPackage(TestCase):
|
||||||
javascript_quote('este texto de app3 debe ser traducido'))
|
javascript_quote('este texto de app3 debe ser traducido'))
|
||||||
|
|
||||||
|
|
||||||
|
skip_selenium = os.environ.get('DJANGO_SKIP_SELENIUM_TESTS', False)
|
||||||
|
|
||||||
|
|
||||||
|
@unittest.skipIf(skip_selenium, 'Selenium tests skipped by explicit request')
|
||||||
@unittest.skipUnless(firefox, 'Selenium not installed')
|
@unittest.skipUnless(firefox, 'Selenium not installed')
|
||||||
class JavascriptI18nTests(LiveServerTestCase):
|
class JavascriptI18nTests(LiveServerTestCase):
|
||||||
urls = 'regressiontests.views.urls'
|
urls = 'regressiontests.views.urls'
|
||||||
|
|
|
@ -301,7 +301,12 @@ if __name__ == "__main__":
|
||||||
'--liveserver', action='store', dest='liveserver', default=None,
|
'--liveserver', action='store', dest='liveserver', default=None,
|
||||||
help='Overrides the default address where the live server (used with '
|
help='Overrides the default address where the live server (used with '
|
||||||
'LiveServerTestCase) is expected to run from. The default value '
|
'LiveServerTestCase) is expected to run from. The default value '
|
||||||
'is localhost:8081.'),
|
'is localhost:8081.')
|
||||||
|
parser.add_option(
|
||||||
|
'--skip-selenium', action='store_true', dest='skip_selenium',
|
||||||
|
default=False,
|
||||||
|
help='Skip running Selenium tests even it Selenium itself is '
|
||||||
|
'installed. By default these tests are not skipped.')
|
||||||
options, args = parser.parse_args()
|
options, args = parser.parse_args()
|
||||||
if options.settings:
|
if options.settings:
|
||||||
os.environ['DJANGO_SETTINGS_MODULE'] = options.settings
|
os.environ['DJANGO_SETTINGS_MODULE'] = options.settings
|
||||||
|
@ -314,6 +319,9 @@ if __name__ == "__main__":
|
||||||
if options.liveserver is not None:
|
if options.liveserver is not None:
|
||||||
os.environ['DJANGO_LIVE_TEST_SERVER_ADDRESS'] = options.liveserver
|
os.environ['DJANGO_LIVE_TEST_SERVER_ADDRESS'] = options.liveserver
|
||||||
|
|
||||||
|
if options.skip_selenium:
|
||||||
|
os.environ['DJANGO_SKIP_SELENIUM_TESTS'] = '1'
|
||||||
|
|
||||||
if options.bisect:
|
if options.bisect:
|
||||||
bisect_tests(options.bisect, options, args)
|
bisect_tests(options.bisect, options, args)
|
||||||
elif options.pair:
|
elif options.pair:
|
||||||
|
|
Loading…
Reference in New Issue