parent
7a5e11bbcf
commit
41f6ea13ce
|
@ -0,0 +1,3 @@
|
||||||
|
Fix the following error during collection of tests inside packages::
|
||||||
|
|
||||||
|
TypeError: object of type 'Package' has no len()
|
|
@ -504,13 +504,14 @@ class Session(nodes.FSCollector):
|
||||||
pkginit = parent.join("__init__.py")
|
pkginit = parent.join("__init__.py")
|
||||||
if pkginit.isfile():
|
if pkginit.isfile():
|
||||||
if pkginit in self._node_cache:
|
if pkginit in self._node_cache:
|
||||||
root = self._node_cache[pkginit]
|
root = self._node_cache[pkginit][0]
|
||||||
else:
|
else:
|
||||||
col = root._collectfile(pkginit)
|
col = root._collectfile(pkginit)
|
||||||
if col:
|
if col:
|
||||||
if isinstance(col[0], Package):
|
if isinstance(col[0], Package):
|
||||||
root = col[0]
|
root = col[0]
|
||||||
self._node_cache[root.fspath] = root
|
# always store a list in the cache, matchnodes expects it
|
||||||
|
self._node_cache[root.fspath] = [root]
|
||||||
|
|
||||||
# If it's a directory argument, recurse and look for any Subpackages.
|
# If it's a directory argument, recurse and look for any Subpackages.
|
||||||
# Let the Package collector deal with subnodes, don't collect here.
|
# Let the Package collector deal with subnodes, don't collect here.
|
||||||
|
@ -530,8 +531,8 @@ class Session(nodes.FSCollector):
|
||||||
if (type(x), x.fspath) in self._node_cache:
|
if (type(x), x.fspath) in self._node_cache:
|
||||||
yield self._node_cache[(type(x), x.fspath)]
|
yield self._node_cache[(type(x), x.fspath)]
|
||||||
else:
|
else:
|
||||||
yield x
|
|
||||||
self._node_cache[(type(x), x.fspath)] = x
|
self._node_cache[(type(x), x.fspath)] = x
|
||||||
|
yield x
|
||||||
else:
|
else:
|
||||||
assert argpath.check(file=1)
|
assert argpath.check(file=1)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
def test():
|
||||||
|
pass
|
|
@ -1591,6 +1591,13 @@ def test_package_collection_infinite_recursion(testdir):
|
||||||
result.stdout.fnmatch_lines("*1 passed*")
|
result.stdout.fnmatch_lines("*1 passed*")
|
||||||
|
|
||||||
|
|
||||||
|
def test_package_collection_init_given_as_argument(testdir):
|
||||||
|
"""Regression test for #3749"""
|
||||||
|
p = testdir.copy_example("collect/package_init_given_as_arg")
|
||||||
|
result = testdir.runpytest(p / "pkg" / "__init__.py")
|
||||||
|
result.stdout.fnmatch_lines("*1 passed*")
|
||||||
|
|
||||||
|
|
||||||
def test_package_with_modules(testdir):
|
def test_package_with_modules(testdir):
|
||||||
"""
|
"""
|
||||||
.
|
.
|
||||||
|
|
Loading…
Reference in New Issue