Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ Authors:
Vladimir Kuznetsov, Roman Prokofyev

Contributors (in the order of first commit):
Alexander Chuklin, Adrien Lemaire, Daniel Boczek
Alexander Chuklin, Adrien Lemaire, Daniel Boczek, Luciano Pacheco (lucmult)
21 changes: 18 additions & 3 deletions django_selenium/jenkins_runner.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from django.dispatch import receiver
from django_jenkins.runner import CITestSuiteRunner
from django_jenkins.signals import build_suite
from django_selenium.selenium_runner import SeleniumTestRunner

class JenkinsTestRunner(CITestSuiteRunner, SeleniumTestRunner):
Expand All @@ -7,13 +9,26 @@ def __init__(self, **kwargs):
self.selenium = True

def build_suite(self, test_labels, **kwargs):
suite = SeleniumTestRunner.build_suite(self, test_labels, **kwargs)
# args and kwargs saved in instance to use in the signal below
self.test_labels = test_labels
self.build_suite_kwargs = kwargs
suite = CITestSuiteRunner.build_suite(self, test_labels, **kwargs)
return suite

def run_tests(self, test_labels, extra_tests=None, **kwargs):

self._start_selenium()
results = super(JenkinsTestRunner, self).run_tests(test_labels, extra_tests, **kwargs)
self._stop_selenium()
try:
results = super(JenkinsTestRunner, self).run_tests(test_labels, extra_tests, **kwargs)
finally:
self._stop_selenium()

return results


@receiver(build_suite)
def add_selenium_tests(sender, suite, **kwargs):
''' Add the selenium test under Jenkins environment '''
sel_suite = sender._get_seltests(sender.test_labels, **sender.build_suite_kwargs)
suite.addTest(sel_suite)

30 changes: 19 additions & 11 deletions django_selenium/selenium_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import unittest

from django_selenium import settings
import django.test.simple
from django.test.simple import reorder_suite
from django.test.testcases import TestCase
from django_selenium.selenium_server import start_test_server
Expand Down Expand Up @@ -57,11 +58,11 @@ def __init__(self, **kwargs):
def _is_start_selenium_server(self):
return bool((settings.SELENIUM_DRIVER == 'Remote') and settings.SELENIUM_PATH)

def build_suite(self, test_labels, extra_tests=None, **kwargs):
def build_suite(self, test_labels, *args, **kwargs):
suite = unittest.TestSuite()

if not self.selenium_only:
suite = super(SeleniumTestRunner, self).build_suite(test_labels, extra_tests, **kwargs)
suite = super(SeleniumTestRunner, self).build_suite(test_labels, *args, **kwargs)

if self.selenium:
# Hack to exclude doctests from selenium-only, they are already present
Expand All @@ -72,18 +73,25 @@ def build_suite(self, test_labels, extra_tests=None, **kwargs):
app = get_app(label)
setattr(app, 'suite', unittest.TestSuite)

# Add tests from seltests.py modules
import django.test.simple
orig_test_module = django.test.simple.TEST_MODULE
django.test.simple.TEST_MODULE = SELTEST_MODULE
try:
sel_suite = super(SeleniumTestRunner, self).build_suite(test_labels, extra_tests, **kwargs)
suite.addTest(sel_suite)
finally:
django.test.simple.TEST_MODULE = orig_test_module

sel_suite = self._get_seltests(test_labels, *args, **kwargs)
suite.addTest(sel_suite)

return reorder_suite(suite, (TestCase,))

def _get_seltests(self, *args, **kwargs):
# Add tests from seltests.py modules
import django.test.simple
orig_test_module = django.test.simple.TEST_MODULE
django.test.simple.TEST_MODULE = SELTEST_MODULE
try:
sel_suite = DjangoTestSuiteRunner.build_suite(self, *args, **kwargs)
finally:
django.test.simple.TEST_MODULE = orig_test_module

return sel_suite


def _start_selenium(self):
if self.selenium:

Expand Down