Skip to content

Commit

Permalink
Added comments and docstrings in accordance to feedback from @nicoddemus
Browse files Browse the repository at this point in the history
.
  • Loading branch information
taschini committed May 30, 2016
1 parent 11b04e0 commit 811f837
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
11 changes: 11 additions & 0 deletions _pytest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,13 @@ def _locate_module(self, modulename, searchpath):
In case of a presumptive namespace package return all of its possible
locations.
Note: The only reliable way to determine whether a package is a
namespace package, i.e., whether its ``__path__`` has more than one
element, is to import it. This method does not do that and hence we
are talking of a *presumptive* namespace package. The ``_parsearg``
method is aware of this and, quite conservatively, tends to raise an
exception in case of doubt.
"""
try:
fd, pathname, type_ = imp.find_module(modulename, searchpath)
Expand All @@ -666,6 +673,10 @@ def _locate_module(self, modulename, searchpath):
return [pathname]
else:
init_file = os.path.join(pathname, '__init__.py')
# The following check is a little heuristic do determine whether a
# package is a namespace package. If its '__init__.py' is empty
# then it should be treated as a regular package (see #1568 for
# further discussion):
if os.path.getsize(init_file) == 0:
return [pathname]
return [pathname] + self._locate_module(
Expand Down
14 changes: 11 additions & 3 deletions testing/acceptance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,10 @@ def join_pythonpath(what):
])

def test_cmdline_python_namespace_package(self, testdir, monkeypatch):
monkeypatch.delenv('PYTHONDONTWRITEBYTECODE', False)
"""
test --pyargs option with namespace packages (#1567)
"""
monkeypatch.delenv('PYTHONDONTWRITEBYTECODE', raising=False)

search_path = []
for dirname in "hello", "world":
Expand Down Expand Up @@ -599,16 +602,21 @@ def join_pythonpath(*dirs):
monkeypatch.syspath_prepend(p)

# mixed module and filenames:
result = testdir.runpytest("--pyargs", "ns_pkg.hello", "world/ns_pkg")
result = testdir.runpytest("--pyargs", "-v", "ns_pkg.hello", "world/ns_pkg")
assert result.ret == 0
result.stdout.fnmatch_lines([
"*test_hello.py::test_hello*PASSED",
"*test_hello.py::test_other*PASSED",
"*test_world.py::test_world*PASSED",
"*test_world.py::test_other*PASSED",
"*4 passed*"
])

# specify tests within a module
result = testdir.runpytest("--pyargs", "ns_pkg.world.test_world::test_other")
result = testdir.runpytest("--pyargs", "-v", "ns_pkg.world.test_world::test_other")
assert result.ret == 0
result.stdout.fnmatch_lines([
"*test_world.py::test_other*PASSED",
"*1 passed*"
])

Expand Down

0 comments on commit 811f837

Please sign in to comment.