Skip to content

Commit 97997d2

Browse files
authored
Merge pull request #969 from gaborbernat/967
Allow plugins to alter the paths config
2 parents 1720459 + edadbec commit 97997d2

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

coverage/config.py

+6
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,9 @@ def set_option(self, option_name, value):
421421
`value` is the new value for the option.
422422
423423
"""
424+
if option_name == "paths":
425+
self.paths = value
426+
return
424427

425428
# Check all the hard-coded options.
426429
for option_spec in self.CONFIG_FILE_OPTIONS:
@@ -448,6 +451,9 @@ def get_option(self, option_name):
448451
Returns the value of the option.
449452
450453
"""
454+
if option_name == "paths":
455+
return self.paths
456+
451457
# Check all the hard-coded options.
452458
for option_spec in self.CONFIG_FILE_OPTIONS:
453459
attr, where = option_spec[:2]

tests/test_config.py

+12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
44

55
"""Test the config file handling for coverage.py"""
6+
from collections import OrderedDict
67

78
import mock
89

@@ -340,6 +341,17 @@ def test_tweaks_after_constructor(self):
340341
self.assertFalse(cov.get_option("run:branch"))
341342
self.assertEqual(cov.get_option("run:data_file"), "fooey.dat")
342343

344+
def test_tweaks_paths_after_constructor(self):
345+
cov = coverage.Coverage()
346+
paths = cov.get_option("paths")
347+
self.assertEqual(paths, OrderedDict())
348+
349+
new_paths = OrderedDict()
350+
new_paths['magic'] = ['src', 'ok']
351+
cov.set_option("paths", new_paths)
352+
353+
self.assertEqual(cov.get_option("paths"), new_paths)
354+
343355
def test_tweak_error_checking(self):
344356
# Trying to set an unknown config value raises an error.
345357
cov = coverage.Coverage()

0 commit comments

Comments
 (0)