diff --git a/tests/runtests.py b/tests/runtests.py index beda3c7..5f9365c 100644 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -4,8 +4,28 @@ import django from django.conf import settings from django.test.utils import get_runner +from functools import wraps +def measure_memory(f): + @wraps(f) + def wrapper(*args, **kwds): + if sys.version_info[:2] >= (3, 4): + import tracemalloc + tracemalloc.start() + + return_value = f(*args, **kwds) + + if sys.version_info[:2] >= (3, 4): + peak = tracemalloc.get_traced_memory()[1] + print("Peak memory usage: {:.3f} MB".format(peak / 10**6)) + tracemalloc.stop() + + return return_value + return wrapper + + +@measure_memory def run_tests(): os.environ['DJANGO_SETTINGS_MODULE'] = 'fstest.settings' django.setup() @@ -13,8 +33,9 @@ def run_tests(): test_runner = TestRunner() # failures = test_runner.run_tests(["minimalapp.tests"]) failures = test_runner.run_tests(None) - sys.exit(bool(failures)) + return failures if __name__ == "__main__": # pragma: no branch - run_tests() + failures = run_tests() + sys.exit(bool(failures))