Skip to content

Commit 350914d

Browse files
committed
Minor cleanup of test_runner.py. Added guards against settings which can make tests inexplicably fail. Updated check to avoid running tests on production server.
- Legacy-Id: 4564
1 parent a5041a2 commit 350914d

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

ietf/utils/test_runner.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@
3333
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3434

3535
import socket
36+
3637
from django.conf import settings
3738
from django.template import TemplateDoesNotExist
39+
from django.test.simple import run_tests as django_run_tests
40+
3841
import ietf.utils.mail
39-
from ietf.utils.mail import outbox as outbox
4042

4143
loaded_templates = set()
4244
test_database_name = None
@@ -72,19 +74,22 @@ def run_tests_1(test_labels, *args, **kwargs):
7274
connection.creation.__class__.create_test_db = safe_create_1
7375
old_destroy = connection.creation.__class__.destroy_test_db
7476
connection.creation.__class__.destroy_test_db = safe_destroy_0_1
75-
from django.test.simple import run_tests
7677
if not test_labels:
7778
settings.TEMPLATE_LOADERS = ('ietf.utils.test_runner.template_coverage_loader',) + settings.TEMPLATE_LOADERS
7879
test_labels = [x.split(".")[-1] for x in settings.INSTALLED_APPS if x.startswith("ietf")] + ['redirects.TemplateCoverageTestCase',]
80+
if settings.SITE_ID != 1:
81+
print " Changing SITE_ID to '1' during testing, to avoid failures due to a missing site entry in the test DB."
82+
settings.SITE_ID = 1
83+
assert(not settings.IDTRACKER_BASE_URL.endswith('/'))
7984
kwargs["verbosity"] = 0
80-
run_tests(test_labels, *args, **kwargs)
85+
django_run_tests(test_labels, *args, **kwargs)
8186

8287
def run_tests(*args, **kwargs):
8388
# Tests that involve switching back and forth between the real
8489
# database and the test database are way too dangerous to run
8590
# against the production database
86-
if socket.gethostname().startswith("core3"):
87-
raise EnvironmentError("Refusing to run tests on core3")
91+
if socket.gethostname().split('.')[0] in ['core3', 'ietfa', 'ietfb', 'ietfc', ]:
92+
raise EnvironmentError("Refusing to run tests on production server")
8893
ietf.utils.mail.test_mode = True
8994
run_tests_1(*args, **kwargs)
9095

0 commit comments

Comments
 (0)