Browse Source

[tests] Give option of code coverage for explicitly mentioned packages

- Earlier, code coverage reporting for was all packages only.
- Now, we have the option to only report coverage for specific packages by adding them as command-line input.

NOTE: Tests run for all packages, only coverage is reported for specific mentioned packages if this option is used.
Harshg999 3 years ago
parent
commit
47f0433152
1 changed files with 13 additions and 1 deletions
  1. 13 1
      desktop/core/src/desktop/lib/test_runners.py

+ 13 - 1
desktop/core/src/desktop/lib/test_runners.py

@@ -82,7 +82,19 @@ class HueTestRunner(NoseTestSuiteRunner):
       nose_argv.extend(args)
 
     if hasattr(settings, 'NOSE_ARGS'):
-      nose_argv.extend(settings.NOSE_ARGS)
+      extended_nose_args = settings.NOSE_ARGS
+
+      # Remove coverage packages option from settings.NOSE_ARGS if explicitly mentioned as test command-line argument.
+      # This will help as an option to report coverage for specific packages only if required.
+      for nose_arg in nose_argv:
+        if nose_arg.startswith('--cover-package'):
+          extended_nose_args = []
+
+          for arg in settings.NOSE_ARGS:
+            if not arg.startswith('--cover-package'):
+              extended_nose_args.append(arg)
+
+      nose_argv.extend(extended_nose_args)
 
     # Skip over 'manage.py test' and any arguments handled by django.
     django_opts = ['--noinput', '--liveserver', '-p', '--pattern']