Merge pull request #7047 from adityahase/measure-tests
feat(tests): Record time required for each test
This commit is contained in:
commit
58c68bb1fd
1 changed files with 15 additions and 1 deletions
|
|
@ -5,6 +5,7 @@ from __future__ import unicode_literals, print_function
|
|||
|
||||
import frappe
|
||||
import unittest, json, sys, os
|
||||
import time
|
||||
import xmlrunner
|
||||
import importlib
|
||||
from frappe.modules import load_doctype_module, get_module_name
|
||||
|
|
@ -90,6 +91,19 @@ def set_test_email_config():
|
|||
"admin_password": "admin"
|
||||
})
|
||||
|
||||
|
||||
class TimeLoggingTestResult(unittest.TextTestResult):
|
||||
def startTest(self, test):
|
||||
self._started_at = time.time()
|
||||
super(TimeLoggingTestResult, self).startTest(test)
|
||||
|
||||
def addSuccess(self, test):
|
||||
elapsed = time.time() - self._started_at
|
||||
name = self.getDescription(test)
|
||||
self.stream.write("\n{} ({:.03}s)\n".format(name, elapsed))
|
||||
super(TimeLoggingTestResult, self).addSuccess(test)
|
||||
|
||||
|
||||
def run_all_tests(app=None, verbose=False, profile=False, ui_tests=False, failfast=False):
|
||||
import os
|
||||
|
||||
|
|
@ -115,7 +129,7 @@ def run_all_tests(app=None, verbose=False, profile=False, ui_tests=False, failfa
|
|||
pr = cProfile.Profile()
|
||||
pr.enable()
|
||||
|
||||
out = unittest_runner(verbosity=1+(verbose and 1 or 0), failfast=failfast).run(test_suite)
|
||||
out = unittest_runner(resultclass=TimeLoggingTestResult, verbosity=1+(verbose and 1 or 0), failfast=failfast).run(test_suite)
|
||||
|
||||
if profile:
|
||||
pr.disable()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue