diff --git a/plugin/setup.py b/plugin/setup.py
--- a/plugin/setup.py
+++ b/plugin/setup.py
@@ -15,7 +15,7 @@
setup(
name='pytest_divide_and_cover',
- version='0.1.6',
+ version='0.2.0',
description='Picky test coverage for pytest',
long_description=LONG_DESCRIPTION,
diff --git a/plugin/src/pytest_divide_and_cover.py b/plugin/src/pytest_divide_and_cover.py
--- a/plugin/src/pytest_divide_and_cover.py
+++ b/plugin/src/pytest_divide_and_cover.py
@@ -60,21 +60,11 @@
paths.append(module_path_)
module_paths.append(module_path_)
coverage_script.new_coverage(test_path, module_paths)
- # This next bit needs to be run under a coverage tracer, with source
- # based on paths. Specifically, it should use the root package from
- # each path
- roots = sorted({path.split('.', 1)[0] for path in paths})
- coverage_script.make_import_coverage(roots)
- print('Covering packages under: {}'.format(roots))
- coverage_script.switch_coverage(coverage_script.import_coverage)
- try:
- for path in paths:
- try:
- importlib.import_module(path)
- except ImportError:
- print('Could not import {}'.format(path))
- finally:
- coverage_script.deactivate_coverage()
+ for path in paths:
+ try:
+ importlib.import_module(path)
+ except ImportError:
+ print('Could not import {}'.format(path))
def pytest_runtest_setup(item):
diff --git a/runner/setup.py b/runner/setup.py
--- a/runner/setup.py
+++ b/runner/setup.py
@@ -15,7 +15,7 @@
setup(
name='divide_and_cover',
- version='0.1.3',
+ version='0.2.0',
description='Picky test coverage runner',
long_description=LONG_DESCRIPTION,
diff --git a/runner/src/divide_and_cover/coverage_handler.py b/runner/src/divide_and_cover/coverage_handler.py
--- a/runner/src/divide_and_cover/coverage_handler.py
+++ b/runner/src/divide_and_cover/coverage_handler.py
@@ -1,8 +1,24 @@
+import os
+import re
import sys
from coverage import cmdline
+PYTHON_FILE = re.compile(r'(.*)\.py')
+
+
+def get_module_names_under(path):
+ for entry in os.listdir(path):
+ if os.path.isdir(os.path.join(path, entry)):
+ if os.path.exists(os.path.join(path, entry, '__init__.py')):
+ yield entry
+ else:
+ match = PYTHON_FILE.fullmatch(entry)
+ if match:
+ yield entry.group(1)
+
+
def insert_unique(lst, item):
if item not in lst:
lst.append(item)
@@ -207,6 +223,11 @@
self.coverage.erase()
self.coverage.start()
+ if os.path.isdir('src'):
+ roots = sorted(set(get_module_names_under('src')))
+ self.make_import_coverage(roots)
+ print('Covering packages under: {}'.format(roots))
+ self.switch_coverage(self.import_coverage)
self.code_ran = True
try:
if options.module:
Comments