File tree Expand file tree Collapse file tree 5 files changed +16
-3
lines changed
example_scripts/collect/package_init_given_as_arg/pkg Expand file tree Collapse file tree 5 files changed +16
-3
lines changed Original file line number Diff line number Diff line change 1+ Fix the following error during collection of tests inside packages::
2+
3+ TypeError: object of type 'Package' has no len()
Original file line number Diff line number Diff line change @@ -504,13 +504,14 @@ def _collect(self, arg):
504504 pkginit = parent .join ("__init__.py" )
505505 if pkginit .isfile ():
506506 if pkginit in self ._node_cache :
507- root = self ._node_cache [pkginit ]
507+ root = self ._node_cache [pkginit ][ 0 ]
508508 else :
509509 col = root ._collectfile (pkginit )
510510 if col :
511511 if isinstance (col [0 ], Package ):
512512 root = col [0 ]
513- self ._node_cache [root .fspath ] = root
513+ # always store a list in the cache, matchnodes expects it
514+ self ._node_cache [root .fspath ] = [root ]
514515
515516 # If it's a directory argument, recurse and look for any Subpackages.
516517 # Let the Package collector deal with subnodes, don't collect here.
@@ -530,8 +531,8 @@ def _collect(self, arg):
530531 if (type (x ), x .fspath ) in self ._node_cache :
531532 yield self ._node_cache [(type (x ), x .fspath )]
532533 else :
533- yield x
534534 self ._node_cache [(type (x ), x .fspath )] = x
535+ yield x
535536 else :
536537 assert argpath .check (file = 1 )
537538
Original file line number Diff line number Diff line change 1+ def test ():
2+ pass
Original file line number Diff line number Diff line change @@ -1591,6 +1591,13 @@ def test_package_collection_infinite_recursion(testdir):
15911591 result .stdout .fnmatch_lines ("*1 passed*" )
15921592
15931593
1594+ def test_package_collection_init_given_as_argument (testdir ):
1595+ """Regression test for #3749"""
1596+ p = testdir .copy_example ("collect/package_init_given_as_arg" )
1597+ result = testdir .runpytest (p / "pkg" / "__init__.py" )
1598+ result .stdout .fnmatch_lines ("*1 passed*" )
1599+
1600+
15941601def test_package_with_modules (testdir ):
15951602 """
15961603 .
You can’t perform that action at this time.
0 commit comments