You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

61 line
1.3 KiB

  1. # Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and Contributors
  2. # MIT License. See LICENSE
  3. """
  4. frappe.coverage
  5. ~~~~~~~~~~~~~~~~
  6. Coverage settings for frappe
  7. """
  8. STANDARD_INCLUSIONS = ["*.py"]
  9. STANDARD_EXCLUSIONS = [
  10. '*.js',
  11. '*.xml',
  12. '*.pyc',
  13. '*.css',
  14. '*.less',
  15. '*.scss',
  16. '*.vue',
  17. '*.html',
  18. '*/test_*',
  19. '*/node_modules/*',
  20. '*/doctype/*/*_dashboard.py',
  21. '*/patches/*',
  22. ]
  23. FRAPPE_EXCLUSIONS = [
  24. "*/tests/*",
  25. "*/commands/*",
  26. "*/frappe/change_log/*",
  27. "*/frappe/exceptions*",
  28. "*frappe/setup.py",
  29. "*/doctype/*/*_dashboard.py",
  30. "*/patches/*",
  31. ]
  32. class CodeCoverage():
  33. def __init__(self, with_coverage, app):
  34. self.with_coverage = with_coverage
  35. self.app = app or 'frappe'
  36. def __enter__(self):
  37. if self.with_coverage:
  38. import os
  39. from coverage import Coverage
  40. from frappe.utils import get_bench_path
  41. # Generate coverage report only for app that is being tested
  42. source_path = os.path.join(get_bench_path(), 'apps', self.app)
  43. omit = STANDARD_EXCLUSIONS[:]
  44. if self.app == 'frappe':
  45. omit.extend(FRAPPE_EXCLUSIONS)
  46. self.coverage = Coverage(source=[source_path], omit=omit, include=STANDARD_INCLUSIONS)
  47. self.coverage.start()
  48. def __exit__(self, exc_type, exc_value, traceback):
  49. if self.with_coverage:
  50. self.coverage.stop()
  51. self.coverage.save()