py3: Switch almost all shebang lines to use `python3`.
This causes `upgrade-zulip-from-git`, as well as a no-option run of
`tools/build-release-tarball`, to produce a Zulip install running
Python 3, rather than Python 2. In particular this means that the
virtualenv we create, in which all application code runs, is Python 3.
One shebang line, on `zulip-ec2-configure-interfaces`, explicitly
keeps Python 2, and at least one external ops script, `wal-e`, also
still runs on Python 2. See discussion on the respective previous
commits that made those explicit. There may also be some other
third-party scripts we use, outside of this source tree and running
outside our virtualenv, that still run on Python 2.
2017-08-02 23:15:16 +02:00
|
|
|
#!/usr/bin/env python3
|
2016-01-23 23:16:14 +01:00
|
|
|
|
2017-07-04 13:12:40 +02:00
|
|
|
from typing import List, Any
|
2018-03-23 17:13:45 +01:00
|
|
|
from mypy_extensions import NoReturn
|
2017-02-19 01:26:52 +01:00
|
|
|
import glob
|
2017-11-09 08:41:47 +01:00
|
|
|
import argparse
|
2016-01-23 23:16:14 +01:00
|
|
|
import os
|
|
|
|
import sys
|
2016-03-12 05:58:35 +01:00
|
|
|
import subprocess
|
2016-12-23 18:42:45 +01:00
|
|
|
import ujson
|
2017-07-04 13:12:40 +02:00
|
|
|
import httplib2
|
2018-05-21 08:02:01 +02:00
|
|
|
import httpretty
|
2017-07-04 15:12:16 +02:00
|
|
|
import requests
|
2016-01-23 23:16:14 +01:00
|
|
|
|
2017-02-05 21:24:28 +01:00
|
|
|
# check for the venv
|
|
|
|
from lib import sanity_check
|
|
|
|
sanity_check.check_venv(__file__)
|
|
|
|
|
|
|
|
import django
|
|
|
|
from django.conf import settings
|
|
|
|
from django.test.utils import get_runner
|
2016-01-23 23:16:14 +01:00
|
|
|
|
2017-02-19 01:26:52 +01:00
|
|
|
target_fully_covered = {path for target in [
|
|
|
|
'analytics/lib/*.py',
|
2017-03-15 01:11:25 +01:00
|
|
|
'analytics/models.py',
|
|
|
|
'analytics/tests/*.py',
|
|
|
|
'analytics/views.py',
|
2017-10-12 04:11:09 +02:00
|
|
|
# zerver/ and zerver/lib/ are important core files
|
|
|
|
'zerver/*.py',
|
2017-10-12 04:08:15 +02:00
|
|
|
'zerver/lib/*.py',
|
2018-08-07 15:43:11 +02:00
|
|
|
# stripe.py handles billing
|
2018-09-25 12:33:30 +02:00
|
|
|
'corporate/lib/stripe.py',
|
2017-04-27 07:52:39 +02:00
|
|
|
# Test files should have 100% coverage; test code that isn't run
|
|
|
|
# is likely a bug in the test.
|
2017-03-05 08:39:34 +01:00
|
|
|
'zerver/tests/*.py',
|
2018-09-25 12:42:23 +02:00
|
|
|
'corporate/tests/*.py',
|
2017-10-12 04:11:09 +02:00
|
|
|
# As a project, we require 100% test coverage in the views files.
|
|
|
|
'zerver/views/*.py',
|
2017-02-19 01:26:52 +01:00
|
|
|
'zproject/backends.py',
|
2017-11-30 07:20:06 +01:00
|
|
|
'confirmation/*.py',
|
2017-08-24 20:32:54 +02:00
|
|
|
'zerver/webhooks/*/*.py',
|
2017-10-12 04:11:09 +02:00
|
|
|
# Once we have a nice negative tests system, we can add these:
|
|
|
|
# 'zerver/webhooks/*/*.py',
|
|
|
|
# 'zerver/webhooks/*/*/*.py',
|
2018-02-25 23:52:38 +01:00
|
|
|
'zerver/worker/queue_processor.py',
|
2017-02-19 01:26:52 +01:00
|
|
|
] for path in glob.glob(target)}
|
|
|
|
|
|
|
|
not_yet_fully_covered = {
|
2017-03-15 01:11:25 +01:00
|
|
|
# Analytics fixtures library is used to generate test fixtures;
|
|
|
|
# isn't properly accounted for in test coverage analysis since it
|
|
|
|
# runs before tests.
|
2017-02-19 01:26:52 +01:00
|
|
|
'analytics/lib/fixtures.py',
|
2017-03-15 01:11:25 +01:00
|
|
|
# We have 100% coverage on the new stuff; need to refactor old stuff.
|
|
|
|
'analytics/views.py',
|
2017-02-19 01:26:52 +01:00
|
|
|
# Major lib files should have 100% coverage
|
2017-10-12 04:08:15 +02:00
|
|
|
'zerver/lib/addressee.py',
|
2017-02-19 01:26:52 +01:00
|
|
|
'zerver/lib/bugdown/__init__.py',
|
2017-10-12 04:08:15 +02:00
|
|
|
'zerver/lib/cache.py',
|
|
|
|
'zerver/lib/cache_helpers.py',
|
2017-02-19 03:52:48 +01:00
|
|
|
'zerver/lib/i18n.py',
|
2017-02-19 01:26:52 +01:00
|
|
|
'zerver/lib/notifications.py',
|
2017-10-12 04:08:15 +02:00
|
|
|
'zerver/lib/send_email.py',
|
|
|
|
# Other lib files that ideally would coverage, but aren't sorted
|
2017-10-12 04:11:09 +02:00
|
|
|
'zerver/__init__.py',
|
|
|
|
'zerver/filters.py',
|
|
|
|
'zerver/middleware.py',
|
2017-10-12 04:08:15 +02:00
|
|
|
'zerver/lib/bot_lib.py',
|
|
|
|
'zerver/lib/camo.py',
|
|
|
|
'zerver/lib/debug.py',
|
|
|
|
'zerver/lib/digest.py',
|
|
|
|
'zerver/lib/email_mirror.py',
|
|
|
|
'zerver/lib/error_notify.py',
|
|
|
|
'zerver/lib/export.py',
|
|
|
|
'zerver/lib/feedback.py',
|
|
|
|
'zerver/lib/fix_unreads.py',
|
|
|
|
'zerver/lib/html_diff.py',
|
2018-04-24 01:23:22 +02:00
|
|
|
'zerver/lib/import_realm.py',
|
2017-10-12 04:08:15 +02:00
|
|
|
'zerver/lib/logging_util.py',
|
|
|
|
'zerver/lib/outgoing_webhook.py',
|
|
|
|
'zerver/lib/parallel.py',
|
|
|
|
'zerver/lib/profile.py',
|
|
|
|
'zerver/lib/queue.py',
|
|
|
|
'zerver/lib/rate_limiter.py',
|
|
|
|
'zerver/lib/sqlalchemy_utils.py',
|
2018-06-02 01:57:06 +02:00
|
|
|
'zerver/lib/storage.py',
|
2017-10-12 04:08:15 +02:00
|
|
|
'zerver/lib/str_utils.py',
|
|
|
|
'zerver/lib/stream_recipient.py',
|
|
|
|
'zerver/lib/timeout.py',
|
|
|
|
'zerver/lib/unminify.py',
|
|
|
|
'zerver/lib/utils.py',
|
2018-08-11 16:26:46 +02:00
|
|
|
'zerver/lib/zephyr.py',
|
2017-10-12 04:08:15 +02:00
|
|
|
# Low priority for coverage
|
|
|
|
'zerver/lib/ccache.py',
|
|
|
|
'zerver/lib/generate_test_data.py',
|
|
|
|
'zerver/lib/test_fixtures.py',
|
|
|
|
'zerver/lib/test_runner.py',
|
2018-01-26 22:40:39 +01:00
|
|
|
'zerver/lib/api_test_helpers.py',
|
2018-08-01 00:18:04 +02:00
|
|
|
# Data import files
|
|
|
|
'zerver/data_import/slack.py',
|
2018-08-01 00:27:06 +02:00
|
|
|
'zerver/data_import/gitter.py',
|
2018-08-02 15:24:34 +02:00
|
|
|
'zerver/data_import/import_util.py',
|
2017-08-24 20:32:54 +02:00
|
|
|
# Webhook integrations with incomplete coverage
|
2018-05-22 16:46:45 +02:00
|
|
|
'zerver/webhooks/github_legacy/view.py',
|
2017-08-24 20:32:54 +02:00
|
|
|
'zerver/webhooks/greenhouse/view.py',
|
|
|
|
'zerver/webhooks/jira/view.py',
|
|
|
|
'zerver/webhooks/librato/view.py',
|
|
|
|
'zerver/webhooks/pivotal/view.py',
|
|
|
|
'zerver/webhooks/semaphore/view.py',
|
|
|
|
'zerver/webhooks/solano/view.py',
|
|
|
|
'zerver/webhooks/taiga/view.py',
|
|
|
|
'zerver/webhooks/teamcity/view.py',
|
|
|
|
'zerver/webhooks/travis/view.py',
|
|
|
|
'zerver/webhooks/zapier/view.py',
|
2017-02-19 01:26:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
enforce_fully_covered = sorted(target_fully_covered - not_yet_fully_covered)
|
|
|
|
|
2016-12-23 18:42:45 +01:00
|
|
|
FAILED_TEST_PATH = 'var/last_test_failure.json'
|
|
|
|
|
2017-12-13 19:38:15 +01:00
|
|
|
def get_failed_tests():
|
|
|
|
# type: () -> List[str]
|
2016-12-23 18:42:45 +01:00
|
|
|
try:
|
|
|
|
with open(FAILED_TEST_PATH, 'r') as f:
|
|
|
|
return ujson.load(f)
|
|
|
|
except IOError:
|
|
|
|
print("var/last_test_failure.json doesn't exist; running all tests.")
|
|
|
|
return []
|
|
|
|
|
2017-12-13 19:38:15 +01:00
|
|
|
def write_failed_tests(failed_tests):
|
|
|
|
# type: (List[str]) -> None
|
2016-12-23 18:42:45 +01:00
|
|
|
if failed_tests:
|
|
|
|
with open(FAILED_TEST_PATH, 'w') as f:
|
|
|
|
ujson.dump(failed_tests, f)
|
|
|
|
|
2017-12-13 19:38:15 +01:00
|
|
|
def block_internet():
|
|
|
|
# type: () -> None
|
2017-07-04 13:12:40 +02:00
|
|
|
# We are blocking internet currently by assuming mostly any test would use
|
|
|
|
# httplib2 to access internet.
|
2018-05-21 08:02:01 +02:00
|
|
|
requests_orig = requests.request
|
|
|
|
|
|
|
|
def internet_guard_requests(*args: Any, **kwargs: Any) -> Any:
|
|
|
|
if httpretty.is_enabled():
|
|
|
|
return requests_orig(*args, **kwargs)
|
2017-07-04 22:13:38 +02:00
|
|
|
raise Exception("Outgoing network requests are not allowed in the Zulip tests. "
|
|
|
|
"More details and advice are available here:"
|
2017-11-16 19:51:44 +01:00
|
|
|
"https://zulip.readthedocs.io/en/latest/testing/testing.html#internet-access-inside-test-suites")
|
2017-07-04 13:12:40 +02:00
|
|
|
|
2018-05-21 08:02:01 +02:00
|
|
|
requests.request = internet_guard_requests
|
|
|
|
|
|
|
|
http2lib_request_orig = httplib2.Http.request
|
|
|
|
|
|
|
|
def internet_guard_httplib2(*args: Any, **kwargs: Any) -> Any:
|
|
|
|
if httpretty.is_enabled():
|
|
|
|
return http2lib_request_orig(*args, **kwargs)
|
|
|
|
raise Exception("Outgoing network requests are not allowed in the Zulip tests. "
|
|
|
|
"More details and advice are available here:"
|
|
|
|
"https://zulip.readthedocs.io/en/latest/testing/testing.html#internet-access-inside-test-suites")
|
|
|
|
httplib2.Http.request = internet_guard_httplib2
|
2017-07-04 13:12:40 +02:00
|
|
|
|
2016-01-23 23:16:14 +01:00
|
|
|
if __name__ == "__main__":
|
2017-07-04 13:12:40 +02:00
|
|
|
block_internet()
|
2016-03-12 05:58:35 +01:00
|
|
|
TOOLS_DIR = os.path.dirname(os.path.abspath(__file__))
|
2016-07-12 19:25:34 +02:00
|
|
|
os.chdir(os.path.dirname(TOOLS_DIR))
|
2016-03-12 05:58:35 +01:00
|
|
|
sys.path.insert(0, os.path.dirname(TOOLS_DIR))
|
2017-03-24 12:48:56 +01:00
|
|
|
|
|
|
|
# Remove proxy settings for running backend tests
|
|
|
|
os.environ["http_proxy"] = ""
|
|
|
|
os.environ["https_proxy"] = ""
|
|
|
|
|
2018-06-06 00:49:48 +02:00
|
|
|
from zerver.lib.test_fixtures import run_generate_fixtures_if_required
|
2016-10-15 17:11:01 +02:00
|
|
|
|
|
|
|
from tools.lib.test_script import (
|
|
|
|
get_provisioning_status,
|
|
|
|
)
|
|
|
|
|
2016-01-23 23:16:14 +01:00
|
|
|
os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.test_settings'
|
|
|
|
# "-u" uses unbuffered IO, which is important when wrapping it in subprocess
|
|
|
|
os.environ['PYTHONUNBUFFERED'] = 'y'
|
|
|
|
|
2017-11-09 08:41:47 +01:00
|
|
|
usage = """test-backend [options]
|
2016-06-27 23:15:30 +02:00
|
|
|
test-backend # Runs all backend tests
|
|
|
|
test-backend zerver.tests.test_bugdown # run all tests in a test module
|
2016-09-28 10:37:58 +02:00
|
|
|
test-backend zerver/tests/test_bugdown.py # run all tests in a test module
|
|
|
|
test-backend test_bugdown # run all tests in a test module
|
2016-06-27 23:15:30 +02:00
|
|
|
test-backend zerver.tests.test_bugdown.BugdownTest # run all tests in a test class
|
2016-09-28 10:37:58 +02:00
|
|
|
test-backend BugdownTest # run all tests in a test class
|
|
|
|
test-backend zerver.tests.test_bugdown.BugdownTest.test_inline_youtube # run a single test
|
|
|
|
test-backend BugdownTest.test_inline_youtube # run a single test"""
|
2016-06-27 23:15:30 +02:00
|
|
|
|
2017-11-22 06:54:27 +01:00
|
|
|
parser = argparse.ArgumentParser(description=usage,
|
|
|
|
formatter_class=argparse.RawTextHelpFormatter)
|
2017-11-09 08:41:47 +01:00
|
|
|
|
|
|
|
parser.add_argument('--nonfatal-errors', action="store_false", default=True,
|
|
|
|
dest="fatal_errors", help="Continue past test failures to run all tests")
|
|
|
|
parser.add_argument('--coverage', dest='coverage',
|
|
|
|
action="store_true",
|
|
|
|
default=False,
|
|
|
|
help='Compute test coverage.')
|
|
|
|
parser.add_argument('--verbose-coverage', dest='verbose_coverage',
|
|
|
|
action="store_true",
|
|
|
|
default=False, help='Enable verbose print of coverage report.')
|
|
|
|
|
|
|
|
parser.add_argument('--processes', dest='processes',
|
|
|
|
type=int,
|
|
|
|
action='store',
|
|
|
|
default=4,
|
|
|
|
help='Specify the number of processes to run the '
|
|
|
|
'tests in. Default is 4.')
|
|
|
|
parser.add_argument('--profile', dest='profile',
|
|
|
|
action="store_true",
|
|
|
|
default=False, help='Profile test runtime.')
|
|
|
|
parser.add_argument('--force', dest='force',
|
|
|
|
action="store_true",
|
|
|
|
default=False, help='Run tests despite possible problems.')
|
|
|
|
parser.add_argument('--no-shallow', dest='no_shallow',
|
|
|
|
action="store_true",
|
|
|
|
default=False,
|
|
|
|
help="Don't allow shallow testing of templates (deprecated)")
|
|
|
|
parser.add_argument('--verbose', dest='verbose',
|
|
|
|
action="store_true",
|
|
|
|
default=False,
|
|
|
|
help="Show detailed output")
|
|
|
|
parser.add_argument('--generate-fixtures', action="store_true", default=False,
|
|
|
|
dest="generate_fixtures",
|
|
|
|
help=("Force a call to generate-fixtures."))
|
|
|
|
parser.add_argument('--report-slow-tests', dest='report_slow_tests',
|
|
|
|
action="store_true",
|
|
|
|
default=False,
|
|
|
|
help="Show which tests are slowest.")
|
|
|
|
parser.add_argument('--reverse', dest='reverse',
|
|
|
|
action="store_true",
|
|
|
|
default=False,
|
|
|
|
help="Run tests in reverse order.")
|
|
|
|
parser.add_argument('--rerun', dest="rerun",
|
|
|
|
action="store_true",
|
|
|
|
default=False,
|
|
|
|
help=("Run the tests which failed the last time "
|
|
|
|
"test-backend was run. Implies --nonfatal-errors."))
|
2018-05-18 13:38:40 +02:00
|
|
|
parser.add_argument('args', nargs='*')
|
2017-11-09 08:41:47 +01:00
|
|
|
|
|
|
|
options = parser.parse_args()
|
|
|
|
args = options.args
|
|
|
|
|
|
|
|
if options.processes < 1:
|
|
|
|
raise argparse.ArgumentError(
|
|
|
|
"option processes: Only positive integers are allowed.")
|
|
|
|
|
2016-09-28 10:37:58 +02:00
|
|
|
zerver_test_dir = 'zerver/tests/'
|
|
|
|
|
2016-12-23 18:42:45 +01:00
|
|
|
# While running --rerun, we read var/last_test_failure.json to get
|
|
|
|
# the list of tests that failed on the last run, and then pretend
|
|
|
|
# those tests were passed explicitly. --rerun implies
|
|
|
|
# --nonfatal-errors, so that we don't end up removing tests from
|
|
|
|
# the list that weren't run.
|
|
|
|
if options.rerun:
|
2017-05-24 01:20:35 +02:00
|
|
|
options.processes = 1
|
2016-12-23 18:42:45 +01:00
|
|
|
options.fatal_errors = False
|
|
|
|
failed_tests = get_failed_tests()
|
|
|
|
if failed_tests:
|
|
|
|
args = failed_tests
|
2017-07-07 22:36:03 +02:00
|
|
|
if len(args) > 0:
|
|
|
|
# If we passed a specific set of tests, run in serial mode.
|
|
|
|
options.processes = 1
|
2016-12-23 18:42:45 +01:00
|
|
|
|
2016-09-28 10:37:58 +02:00
|
|
|
# to transform forward slashes '/' present in the argument into dots '.'
|
|
|
|
for suite in args:
|
2016-10-07 06:53:26 +02:00
|
|
|
args[args.index(suite)] = suite.rstrip('/').replace("/", ".")
|
2016-09-28 10:37:58 +02:00
|
|
|
|
2017-12-13 19:38:15 +01:00
|
|
|
def rewrite_arguments(search_key):
|
|
|
|
# type: (str) -> None
|
2016-11-03 21:38:06 +01:00
|
|
|
for root, dirs, files_names in os.walk(zerver_test_dir, topdown=False):
|
|
|
|
for file_name in files_names:
|
|
|
|
# Check for files starting with alphanumeric characters and ending with '.py'
|
|
|
|
# Ignore backup files if any
|
|
|
|
if not file_name[0].isalnum() or not file_name.endswith(".py"):
|
2016-09-28 20:51:41 +02:00
|
|
|
continue
|
2016-11-03 21:38:06 +01:00
|
|
|
filepath = os.path.join(root, file_name)
|
2016-09-28 20:51:41 +02:00
|
|
|
for line in open(filepath):
|
2016-11-03 21:38:06 +01:00
|
|
|
if search_key not in line:
|
|
|
|
continue
|
|
|
|
new_suite = filepath.replace(".py", ".") + suite
|
|
|
|
args[args.index(suite)] = new_suite
|
|
|
|
return
|
2016-09-28 20:51:41 +02:00
|
|
|
|
2016-09-28 10:37:58 +02:00
|
|
|
for suite in args:
|
|
|
|
if suite[0].isupper() and "test_" in suite:
|
|
|
|
classname = suite.rsplit('.', 1)[0]
|
2016-09-28 20:51:41 +02:00
|
|
|
rewrite_arguments(classname)
|
2016-09-28 10:37:58 +02:00
|
|
|
elif suite[0].isupper():
|
2017-06-16 08:20:03 +02:00
|
|
|
rewrite_arguments('class %s(' % (suite,))
|
2016-09-28 10:37:58 +02:00
|
|
|
|
|
|
|
for suite in args:
|
|
|
|
if suite.startswith('test'):
|
2016-11-03 21:38:06 +01:00
|
|
|
for root, dirs, files_names in os.walk(zerver_test_dir):
|
|
|
|
for file_name in files_names:
|
|
|
|
if file_name == suite or file_name == suite + ".py":
|
|
|
|
new_suite = os.path.join(root, file_name)
|
|
|
|
args[args.index(suite)] = new_suite
|
|
|
|
break
|
2016-09-28 10:37:58 +02:00
|
|
|
|
|
|
|
for suite in args:
|
|
|
|
args[args.index(suite)] = suite.replace(".py", "")
|
|
|
|
|
|
|
|
# to transform forward slashes '/' introduced by the zerver_test_dir into dots '.'
|
|
|
|
# taking care of any forward slashes that might be present
|
|
|
|
for suite in args:
|
|
|
|
args[args.index(suite)] = suite.replace("/", ".")
|
|
|
|
|
2016-11-19 01:28:28 +01:00
|
|
|
full_suite = len(args) == 0
|
|
|
|
|
2016-01-23 23:16:14 +01:00
|
|
|
if len(args) == 0:
|
2018-03-31 04:13:44 +02:00
|
|
|
suites = [
|
|
|
|
"zerver.tests",
|
|
|
|
"zerver.webhooks",
|
|
|
|
"analytics.tests",
|
2018-09-25 12:42:23 +02:00
|
|
|
"corporate.tests",
|
2018-03-31 04:13:44 +02:00
|
|
|
]
|
2016-01-23 23:16:14 +01:00
|
|
|
else:
|
|
|
|
suites = args
|
|
|
|
|
2016-10-15 17:37:37 +02:00
|
|
|
if not options.force:
|
|
|
|
ok, msg = get_provisioning_status()
|
|
|
|
if not ok:
|
|
|
|
print(msg)
|
|
|
|
print('If you really know what you are doing, use --force to run anyway.')
|
|
|
|
sys.exit(1)
|
2016-10-15 17:11:01 +02:00
|
|
|
|
2016-01-23 23:16:14 +01:00
|
|
|
if options.coverage:
|
2017-06-06 10:04:20 +02:00
|
|
|
import coverage
|
2017-06-06 10:15:54 +02:00
|
|
|
cov = coverage.Coverage(config_file="tools/coveragerc", concurrency='multiprocessing')
|
2016-01-23 23:16:14 +01:00
|
|
|
cov.start()
|
2016-01-24 02:21:34 +01:00
|
|
|
if options.profile:
|
|
|
|
import cProfile
|
|
|
|
prof = cProfile.Profile()
|
|
|
|
prof.enable()
|
2016-11-19 01:28:28 +01:00
|
|
|
|
|
|
|
# This is kind of hacky, but it's the most reliable way
|
|
|
|
# to make sure instrumentation decorators know the
|
|
|
|
# setting when they run.
|
|
|
|
os.environ['TEST_INSTRUMENT_URL_COVERAGE'] = 'TRUE'
|
2016-01-23 23:16:14 +01:00
|
|
|
|
2016-06-21 04:49:45 +02:00
|
|
|
# setup() needs to be called after coverage is started to get proper coverage reports of model
|
|
|
|
# files, since part of setup is importing the models for all applications in INSTALLED_APPS.
|
|
|
|
django.setup()
|
|
|
|
|
2018-06-06 00:49:48 +02:00
|
|
|
run_generate_fixtures_if_required(options.generate_fixtures)
|
2016-03-12 05:58:35 +01:00
|
|
|
|
2017-05-25 20:12:33 +02:00
|
|
|
subprocess.check_call(['tools/webpack', '--test'])
|
2017-05-24 00:03:53 +02:00
|
|
|
|
2016-01-23 23:16:14 +01:00
|
|
|
TestRunner = get_runner(settings)
|
2017-03-22 05:13:44 +01:00
|
|
|
parallel = options.processes
|
|
|
|
|
|
|
|
if parallel > 1:
|
|
|
|
print("-- Running tests in parallel mode with {} "
|
|
|
|
"processes.".format(parallel))
|
|
|
|
else:
|
|
|
|
print("-- Running tests in serial mode.")
|
|
|
|
|
2017-02-10 05:49:28 +01:00
|
|
|
test_runner = TestRunner(failfast=options.fatal_errors, verbosity=2,
|
2017-03-22 11:57:07 +01:00
|
|
|
parallel=parallel, reverse=options.reverse,
|
|
|
|
keepdb=True)
|
2016-12-23 18:42:45 +01:00
|
|
|
failures, failed_tests = test_runner.run_tests(suites, full_suite=full_suite)
|
|
|
|
write_failed_tests(failed_tests)
|
2016-01-23 23:16:14 +01:00
|
|
|
|
2016-05-20 14:53:47 +02:00
|
|
|
templates_not_rendered = test_runner.get_shallow_tested_templates()
|
2017-01-20 19:56:03 +01:00
|
|
|
# We only check the templates if all the tests ran and passed
|
|
|
|
if not failures and full_suite and templates_not_rendered:
|
2016-05-20 14:53:47 +02:00
|
|
|
missed_count = len(templates_not_rendered)
|
2016-12-01 00:38:19 +01:00
|
|
|
print("\nError: %s templates have no tests!" % (missed_count,))
|
2016-11-30 01:38:12 +01:00
|
|
|
for template in templates_not_rendered:
|
|
|
|
print(' {}'.format(template))
|
2016-12-01 01:03:42 +01:00
|
|
|
print("See zerver/tests/test_templates.py for the exclude list.")
|
2016-11-15 13:41:12 +01:00
|
|
|
failures = True
|
2016-05-20 14:53:47 +02:00
|
|
|
|
2016-01-23 23:16:14 +01:00
|
|
|
if options.coverage:
|
|
|
|
cov.stop()
|
|
|
|
cov.save()
|
2017-06-06 10:15:54 +02:00
|
|
|
cov.combine()
|
2017-06-06 12:06:41 +02:00
|
|
|
cov.data_suffix = False # Disable suffix so that filename is .coverage
|
|
|
|
cov.save()
|
2016-06-16 00:05:07 +02:00
|
|
|
if options.verbose_coverage:
|
|
|
|
print("Printing coverage data")
|
|
|
|
cov.report(show_missing=False)
|
2016-07-13 10:49:26 +02:00
|
|
|
cov.html_report(directory='var/coverage')
|
2017-03-23 19:59:24 +01:00
|
|
|
print("HTML report saved; visit at http://127.0.0.1:9991/coverage/index.html")
|
2017-02-19 01:26:52 +01:00
|
|
|
if full_suite and not failures and options.coverage:
|
|
|
|
# Assert that various files have full coverage
|
|
|
|
for path in enforce_fully_covered:
|
|
|
|
missing_lines = cov.analysis2(path)[3]
|
|
|
|
if len(missing_lines) > 0:
|
|
|
|
print("ERROR: %s no longer has complete backend test coverage" % (path,))
|
|
|
|
print(" Lines missing coverage: %s" % (missing_lines,))
|
|
|
|
print()
|
|
|
|
failures = True
|
|
|
|
if failures:
|
|
|
|
print("It looks like your changes lost 100% test coverage in one or more files")
|
|
|
|
print("Usually, the right fix for this is to add some tests.")
|
|
|
|
print("But also check out the include/exclude lists in tools/test-backend.")
|
2017-03-05 08:46:59 +01:00
|
|
|
print("If this line intentionally is not tested, you can use a # nocoverage comment.")
|
2017-02-19 01:26:52 +01:00
|
|
|
print("To run this check locally, use `test-backend --coverage`.")
|
2018-04-06 21:42:22 +02:00
|
|
|
ok = True
|
|
|
|
for path in not_yet_fully_covered:
|
|
|
|
try:
|
|
|
|
missing_lines = cov.analysis2(path)[3]
|
|
|
|
if len(missing_lines) == 0:
|
|
|
|
print("ERROR: %s has complete backend test coverage but is still in not_yet_fully_covered." % (path,))
|
|
|
|
ok = False
|
|
|
|
except coverage.misc.NoSource:
|
|
|
|
continue
|
|
|
|
if not ok:
|
|
|
|
print()
|
|
|
|
print("There are one or more fully covered files that are still in not_yet_fully_covered.")
|
|
|
|
print("Remove the file(s) from not_yet_fully_covered in `tools/test-backend`.")
|
|
|
|
failures = True
|
2016-01-24 02:21:34 +01:00
|
|
|
if options.profile:
|
|
|
|
prof.disable()
|
|
|
|
prof.dump_stats("/tmp/profile.data")
|
|
|
|
print("Profile data saved to /tmp/profile.data")
|
2017-08-23 00:44:14 +02:00
|
|
|
print("You can visualize it using e.g. `snakeviz /tmp/profile.data`")
|
2017-09-04 14:35:08 +02:00
|
|
|
print("Note: If you are using vagrant for development environment you will need to do:")
|
|
|
|
print("1.) `vagrant ssh -- -L 8080:127.0.0.1:8080`")
|
|
|
|
print("2.) `snakeviz -s /tmp/profile.data`")
|
2016-01-23 23:16:14 +01:00
|
|
|
|
2016-07-29 19:48:43 +02:00
|
|
|
if options.report_slow_tests:
|
|
|
|
from zerver.lib.test_runner import report_slow_tests
|
|
|
|
# We do this even with failures, since slowness can be
|
|
|
|
# an important clue as to why tests fail.
|
|
|
|
report_slow_tests()
|
|
|
|
|
2017-02-10 05:48:15 +01:00
|
|
|
# We'll have printed whether tests passed or failed above
|
2016-01-23 23:16:14 +01:00
|
|
|
sys.exit(bool(failures))
|