Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow plugins to alter the paths config #969

Merged
merged 1 commit into from Apr 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions coverage/config.py
Expand Up @@ -421,6 +421,9 @@ def set_option(self, option_name, value):
`value` is the new value for the option.

"""
if option_name == "paths":
self.paths = value
return

# Check all the hard-coded options.
for option_spec in self.CONFIG_FILE_OPTIONS:
Expand Down Expand Up @@ -448,6 +451,9 @@ def get_option(self, option_name):
Returns the value of the option.

"""
if option_name == "paths":
return self.paths

# Check all the hard-coded options.
for option_spec in self.CONFIG_FILE_OPTIONS:
attr, where = option_spec[:2]
Expand Down
12 changes: 12 additions & 0 deletions tests/test_config.py
Expand Up @@ -3,6 +3,7 @@
# For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt

"""Test the config file handling for coverage.py"""
from collections import OrderedDict

import mock

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

def test_tweaks_paths_after_constructor(self):
cov = coverage.Coverage()
paths = cov.get_option("paths")
self.assertEqual(paths, OrderedDict())

new_paths = OrderedDict()
new_paths['magic'] = ['src', 'ok']
cov.set_option("paths", new_paths)

self.assertEqual(cov.get_option("paths"), new_paths)

def test_tweak_error_checking(self):
# Trying to set an unknown config value raises an error.
cov = coverage.Coverage()
Expand Down