def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[], nodatabase=False): """ Test runner which displays a code coverage report at the end of the run. """ coverage.use_cache(0) coverage.start() if nodatabase: results = nodatabase_run_tests(test_labels, verbosity, interactive, extra_tests) else: results = django_test_runner(test_labels, verbosity, interactive, extra_tests) coverage.stop() coverage_modules = [] if test_labels: for label in test_labels: # Don't report coverage if you're only running a single # test case. if '.' not in label: app = get_app(label) coverage_modules.extend(get_all_coverage_modules(app)) else: for app in get_apps(): coverage_modules.extend(get_all_coverage_modules(app)) if coverage_modules: coverage.report(coverage_modules, show_missing=1) return results
def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[], nodatabase=False): """ Test runner which displays a code coverage report at the end of the run. """ test_labels = test_labels or getattr(settings, "TEST_APPS", None) cover_branch = getattr(settings, "COVERAGE_BRANCH_COVERAGE", False) cov = coverage.coverage(branch=cover_branch, cover_pylib=False) cov.use_cache(0) cov.start() if nodatabase: results = nodatabase_run_tests(test_labels, verbosity, interactive, extra_tests) else: from django.db import connection connection.creation.destroy_test_db = lambda *a, **k: None results = django_test_runner(test_labels, verbosity, interactive, extra_tests) cov.stop() coverage_modules = [] if test_labels: for label in test_labels: # Don't report coverage if you're only running a single # test case. if '.' not in label: app = get_app(label) coverage_modules.extend(get_all_coverage_modules(app)) else: for app in get_apps(): coverage_modules.extend(get_all_coverage_modules(app)) morfs = filter(is_wanted_module, coverage_modules) report_methd = cov.report if getattr(settings, "COVERAGE_HTML_REPORT", False) or \ os.environ.get("COVERAGE_HTML_REPORT"): output_dir = getattr(settings, "COVERAGE_HTML_DIRECTORY", "covhtml") report_method = curry(cov.html_report, directory=output_dir) else: report_method = cov.report morfs and report_method(morfs=morfs) return results
def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[], nodatabase=False, xml_out=False): """ Test runner which displays a code coverage report at the end of the run. """ cov = coverage.coverage() cov.erase() cov.use_cache(0) cov.start() if nodatabase: results = nodatabase_run_tests(test_labels, verbosity, interactive, extra_tests) else: results = django_test_runner(test_labels, verbosity, interactive, extra_tests) cov.stop() coverage_modules = [] if test_labels: for label in test_labels: # Don't report coverage if you're only running a single # test case. if '.' not in label: app = get_app(label) coverage_modules.extend(get_all_coverage_modules(app)) else: for app in get_apps(): coverage_modules.extend(get_all_coverage_modules(app)) if coverage_modules: if xml_out: # using the same output directory as the --xml function uses for testing if not os.path.isdir(os.path.join("temp", "xml")): os.makedirs(os.path.join("temp", "xml")) output_filename = 'temp/xml/coverage_output.xml' cov.xml_report(morfs=coverage_modules, outfile=output_filename) cov.report(coverage_modules, show_missing=1) return results
def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[], nodatabase=False, xml_out=False, callgraph=False, html_only=False): """ Test runner which displays a code coverage report at the end of the run. """ cov = coverage.coverage() cov.erase() cov.use_cache(0) test_labels = test_labels or getattr(settings, "TEST_APPS", None) cover_branch = getattr(settings, "COVERAGE_BRANCH_COVERAGE", False) cov = coverage.coverage(branch=cover_branch, cover_pylib=False) cov.use_cache(0) coverage_modules = [] if test_labels: for label in test_labels: # Don't report coverage if you're only running a single # test case. if '.' not in label: app = get_app(label) coverage_modules.extend(get_all_coverage_modules(app)) else: for app in get_apps(): coverage_modules.extend(get_all_coverage_modules(app)) morfs = filter(is_wanted_module, coverage_modules) if callgraph: try: import pycallgraph #_include = [i.__name__ for i in coverage_modules] _included = getattr(settings, "COVERAGE_INCLUDE_MODULES", []) _excluded = getattr(settings, "COVERAGE_EXCLUDE_MODULES", []) _included = [i.strip('*')+'*' for i in _included] _excluded = [i.strip('*')+'*' for i in _included] _filter_func = pycallgraph.GlobbingFilter( include=_included or ['*'], #include=['lotericas.*'], #exclude=[], #max_depth=options.max_depth, ) pycallgraph_enabled = True except ImportError: pycallgraph_enabled = False else: pycallgraph_enabled = False cov.start() if pycallgraph_enabled: pycallgraph.start_trace(filter_func=_filter_func) if nodatabase: results = nodatabase_run_tests(test_labels, verbosity, interactive, extra_tests) else: tr = django_test_runner(verbosity, interactive) results = tr.run_tests(test_labels, extra_tests) #results = django_test_runner(test_labels, verbosity, interactive, # extra_tests) if callgraph and pycallgraph_enabled: pycallgraph.stop_trace() cov.stop() if getattr(settings, "COVERAGE_HTML_REPORT", False) or \ os.environ.get("COVERAGE_HTML_REPORT"): output_dir = getattr(settings, "COVERAGE_HTML_DIRECTORY", "covhtml") report_method = curry(cov.html_report, directory=output_dir) if callgraph and pycallgraph_enabled: callgraph_path = output_dir + '/' + 'callgraph.png' pycallgraph.make_dot_graph(callgraph_path) print >>sys.stdout print >>sys.stdout, "Coverage HTML reports were output to '%s'" %output_dir if callgraph: if pycallgraph_enabled: print >>sys.stdout, "Call graph was output to '%s'" %callgraph_path else: print >>sys.stdout, "Call graph was not generated: Install 'pycallgraph' module to do so" else: report_method = cov.report if coverage_modules: if xml_out: # using the same output directory as the --xml function uses for testing if not os.path.isdir(os.path.join("temp", "xml")): os.makedirs(os.path.join("temp", "xml")) output_filename = 'temp/xml/coverage_output.xml' cov.xml_report(morfs=coverage_modules, outfile=output_filename) if not html_only: cov.report(coverage_modules, show_missing=1) return results
def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[], nodatabase=False, xml_out=False, callgraph=False): """ Test runner which displays a code coverage report at the end of the run. """ cov = coverage.coverage() cov.erase() cov.use_cache(0) test_labels = test_labels or getattr(settings, "TEST_APPS", None) cover_branch = getattr(settings, "COVERAGE_BRANCH_COVERAGE", False) cov = coverage.coverage(branch=cover_branch, cover_pylib=False) cov.use_cache(0) coverage_modules = [] if test_labels: for label in test_labels: # Don't report coverage if you're only running a single # test case. if '.' not in label: app = get_app(label) coverage_modules.extend(get_all_coverage_modules(app)) else: for app in get_apps(): coverage_modules.extend(get_all_coverage_modules(app)) morfs = filter(is_wanted_module, coverage_modules) if callgraph: try: import pycallgraph #_include = [i.__name__ for i in coverage_modules] _included = getattr(settings, "COVERAGE_INCLUDE_MODULES", []) _excluded = getattr(settings, "COVERAGE_EXCLUDE_MODULES", []) _included = [i.strip('*') + '*' for i in _included] _excluded = [i.strip('*') + '*' for i in _included] _filter_func = pycallgraph.GlobbingFilter( include=_included or ['*'], #include=['lotericas.*'], #exclude=[], #max_depth=options.max_depth, ) pycallgraph_enabled = True except ImportError: pycallgraph_enabled = False else: pycallgraph_enabled = False cov.start() if pycallgraph_enabled: pycallgraph.start_trace(filter_func=_filter_func) if nodatabase: results = nodatabase_run_tests(test_labels, verbosity, interactive, extra_tests) else: results = django_test_runner(test_labels, verbosity, interactive, extra_tests) if callgraph and pycallgraph_enabled: pycallgraph.stop_trace() cov.stop() report_methd = cov.report if getattr(settings, "COVERAGE_HTML_REPORT", False) or \ os.environ.get("COVERAGE_HTML_REPORT"): output_dir = getattr(settings, "COVERAGE_HTML_DIRECTORY", "covhtml") report_method = curry(cov.html_report, directory=output_dir) if callgraph and pycallgraph_enabled: callgraph_path = output_dir + '/' + 'callgraph.png' pycallgraph.make_dot_graph(callgraph_path) print >> sys.stdout print >> sys.stdout, "Coverage HTML reports were output to '%s'" % output_dir if callgraph: if pycallgraph_enabled: print >> sys.stdout, "Call graph was output to '%s'" % callgraph_path else: print >> sys.stdout, "Call graph was not generated: Install 'pycallgraph' module to do so" else: report_method = cov.report if coverage_modules: if xml_out: # using the same output directory as the --xml function uses for testing if not os.path.isdir(os.path.join("temp", "xml")): os.makedirs(os.path.join("temp", "xml")) output_filename = 'temp/xml/coverage_output.xml' cov.xml_report(morfs=coverage_modules, outfile=output_filename) cov.report(coverage_modules, show_missing=1) return results