Skip to content

Commit

Permalink
Added memory measurement for tests. (Tests use <10MB of memory.)
Browse files Browse the repository at this point in the history
  • Loading branch information
Travis Dart committed Jul 24, 2020
1 parent b2bfad3 commit 98aee59
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions tests/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,38 @@
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()
TestRunner = get_runner(settings)
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))

0 comments on commit 98aee59

Please sign in to comment.