Advertisement
mwchase

divide-and-cover collected diff

Jul 21st, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 3.11 KB | None | 0 0
  1. diff --git a/plugin/setup.py b/plugin/setup.py
  2. --- a/plugin/setup.py
  3. +++ b/plugin/setup.py
  4. @@ -15,7 +15,7 @@
  5.  setup(
  6.      name='pytest_divide_and_cover',
  7.  
  8. -    version='0.1.6',
  9. +    version='0.2.0',
  10.  
  11.      description='Picky test coverage for pytest',
  12.      long_description=LONG_DESCRIPTION,
  13. diff --git a/plugin/src/pytest_divide_and_cover.py b/plugin/src/pytest_divide_and_cover.py
  14. --- a/plugin/src/pytest_divide_and_cover.py
  15. +++ b/plugin/src/pytest_divide_and_cover.py
  16. @@ -60,21 +60,11 @@
  17.                  paths.append(module_path_)
  18.                  module_paths.append(module_path_)
  19.              coverage_script.new_coverage(test_path, module_paths)
  20. -        # This next bit needs to be run under a coverage tracer, with source
  21. -        # based on paths. Specifically, it should use the root package from
  22. -        # each path
  23. -        roots = sorted({path.split('.', 1)[0] for path in paths})
  24. -        coverage_script.make_import_coverage(roots)
  25. -        print('Covering packages under: {}'.format(roots))
  26. -        coverage_script.switch_coverage(coverage_script.import_coverage)
  27. -        try:
  28. -            for path in paths:
  29. -                try:
  30. -                    importlib.import_module(path)
  31. -                except ImportError:
  32. -                    print('Could not import {}'.format(path))
  33. -        finally:
  34. -            coverage_script.deactivate_coverage()
  35. +        for path in paths:
  36. +            try:
  37. +                importlib.import_module(path)
  38. +            except ImportError:
  39. +                print('Could not import {}'.format(path))
  40.  
  41.  
  42.  def pytest_runtest_setup(item):
  43. diff --git a/runner/setup.py b/runner/setup.py
  44. --- a/runner/setup.py
  45. +++ b/runner/setup.py
  46. @@ -15,7 +15,7 @@
  47.  setup(
  48.      name='divide_and_cover',
  49.  
  50. -    version='0.1.3',
  51. +    version='0.2.0',
  52.  
  53.      description='Picky test coverage runner',
  54.      long_description=LONG_DESCRIPTION,
  55. diff --git a/runner/src/divide_and_cover/coverage_handler.py b/runner/src/divide_and_cover/coverage_handler.py
  56. --- a/runner/src/divide_and_cover/coverage_handler.py
  57. +++ b/runner/src/divide_and_cover/coverage_handler.py
  58. @@ -1,8 +1,24 @@
  59. +import os
  60. +import re
  61.  import sys
  62.  
  63.  from coverage import cmdline
  64.  
  65.  
  66. +PYTHON_FILE = re.compile(r'(.*)\.py')
  67. +
  68. +
  69. +def get_module_names_under(path):
  70. +    for entry in os.listdir(path):
  71. +        if os.path.isdir(os.path.join(path, entry)):
  72. +            if os.path.exists(os.path.join(path, entry, '__init__.py')):
  73. +                yield entry
  74. +        else:
  75. +            match = PYTHON_FILE.fullmatch(entry)
  76. +            if match:
  77. +                yield entry.group(1)
  78. +
  79. +
  80.  def insert_unique(lst, item):
  81.      if item not in lst:
  82.          lst.append(item)
  83. @@ -207,6 +223,11 @@
  84.                  self.coverage.erase()
  85.  
  86.          self.coverage.start()
  87. +        if os.path.isdir('src'):
  88. +            roots = sorted(set(get_module_names_under('src')))
  89. +            self.make_import_coverage(roots)
  90. +            print('Covering packages under: {}'.format(roots))
  91. +            self.switch_coverage(self.import_coverage)
  92.          self.code_ran = True
  93.          try:
  94.              if options.module:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement