Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 263f3e1

Browse filesBrowse files
committed
Docs and cleanup for source_pkgs
1 parent ecd6ab1 commit 263f3e1
Copy full SHA for 263f3e1

File tree

8 files changed

+31
-9
lines changed
Filter options

8 files changed

+31
-9
lines changed

‎CHANGES.rst

Copy file name to clipboardExpand all lines: CHANGES.rst
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ want to know what's different in 5.0 since 4.5.x, see :ref:`whatsnew5x`.
2525
Unreleased
2626
----------
2727

28+
- The ``source`` setting has always been interpreted as either a file path or a
29+
module, depending on which existed. If both interpretations were valid, it
30+
was assumed to be a file path. The new ``source_pkgs`` setting can be used
31+
to name a package to disambiguate this case. Thanks, Thomas Grainger. Fixes
32+
`issue 268`_.
33+
34+
.. _issue 268: https://github.com/nedbat/coveragepy/issues/268
35+
2836

2937
.. _changes_521:
3038

‎coverage/control.py

Copy file name to clipboardExpand all lines: coverage/control.py
+8-1Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def __init__(
101101
auto_data=False, timid=None, branch=None, config_file=True,
102102
source=None, source_pkgs=None, omit=None, include=None, debug=None,
103103
concurrency=None, check_preimported=False, context=None,
104-
):
104+
): # pylint: disable=too-many-arguments
105105
"""
106106
Many of these arguments duplicate and override values that can be
107107
provided in a configuration file. Parameters that are missing here
@@ -146,6 +146,10 @@ def __init__(
146146
in the trees indicated by the file paths or package names will be
147147
measured.
148148
149+
`source_pkgs` is a list of package names. It works the same as
150+
`source`, but can be used to name packages where the name can also be
151+
interpreted as a file path.
152+
149153
`include` and `omit` are lists of file name patterns. Files that match
150154
`include` will be measured, files that match `omit` will not. Each
151155
will also accept a single string argument.
@@ -176,6 +180,9 @@ def __init__(
176180
.. versionadded:: 5.0
177181
The `check_preimported` and `context` parameters.
178182
183+
.. versionadded:: 5.3
184+
The `source_pkgs` parameter.
185+
179186
"""
180187
# data_file=None means no disk file at all. data_file missing means
181188
# use the value from the config file.

‎coverage/version.py

Copy file name to clipboardExpand all lines: coverage/version.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# This file is exec'ed in setup.py, don't import anything!
66

77
# Same semantics as sys.version_info.
8-
version_info = (5, 2, 2, "alpha", 0)
8+
version_info = (5, 3, 0, "alpha", 0)
99

1010

1111
def _make_version(major, minor, micro, releaselevel, serial):

‎doc/config.rst

Copy file name to clipboardExpand all lines: doc/config.rst
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,14 @@ for details.
208208
measure during execution. If set, ``include`` is ignored. See :ref:`source`
209209
for details.
210210

211+
.. _config_run_source_pkgs:
212+
213+
``source_pkgs`` (multi-string): a list of packages, the source to measure
214+
during execution. Operates the same as ``source``, but only names packages,
215+
for resolving ambiguities between packages and directories.
216+
217+
.. versionadded:: 5.3
218+
211219
.. _config_run_timid:
212220

213221
``timid`` (boolean, default False): use a simpler but slower trace method.
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("Ambiguous pkg1")
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
amb = 1
2+
amb = 2

‎tests/modules/usepkgs.py

Copy file name to clipboardExpand all lines: tests/modules/usepkgs.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
import pkg2.p2a, pkg2.p2b
66
import othermods.othera, othermods.otherb
77
import othermods.sub.osa, othermods.sub.osb
8+
import ambigious, ambigious.pkg1.ambigious

‎tests/test_api.py

Copy file name to clipboardExpand all lines: tests/test_api.py
+2-7Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -940,13 +940,8 @@ def test_ambigious_source_package_as_dir(self):
940940
self.chdir(self.nice_file(TESTS_DIR, 'modules', "ambigious"))
941941
# pkg1 defaults to directory because tests/modules/ambigious/pkg1 exists
942942
lines = self.coverage_usepkgs(source=["pkg1"])
943-
self.assertEqual(
944-
self.coverage_usepkgs(source=["pkg1"]),
945-
{
946-
u"__init__.py": 0, u"__init__": 0,
947-
u"ambigious.py": 0, u"ambigious": 0,
948-
},
949-
)
943+
self.filenames_in(lines, "ambigious")
944+
self.filenames_not_in(lines, "p1a p1b p1c")
950945

951946
def test_ambigious_source_package_as_package(self):
952947
# pkg1 is a directory and a pkg, since we cd into tests/modules/ambigious

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.