[Python-Dev] 3.5 unittest does not support namespace packages for discovering

Paul Moore p.f.moore at gmail.com
Thu Mar 23 18:15:04 EDT 2017


On 23 March 2017 at 20:41, Ned Batchelder <ned at nedbatchelder.com> wrote:
>>> If unittests searches normal directly, it may walk deep into very
>>> large tree containing
>>> millions of directories.  I don't like it.
>
>> That is a risk, OTOH I think the failure to do what folk expect is a
>> bigger risk.
>
> The issue here is, what do folks expect?  PEP 420 is pretty clear on its
> purpose.

The unittest docs say
(https://docs.python.org/3.6/library/unittest.html#test-discovery)

"""
Unittest supports simple test discovery. In order to be compatible
with test discovery, all of the test files must be modules or packages
(including namespace packages) importable from the top-level directory
of the project (this means that their filenames must be valid
identifiers).
"""

Personally, that to me pretty clearly implies that namespace packages
*should* work. They are explicitly mentioned, after all. I agree that
the implication that any random directory will get scanned is
unexpected - after all *I* know which directories I intended to be
namespace packages, it's just the computer that doesn't. Either way,
someone is likely to get surprised. But I'd argue that if we retain
the current __init__.py check, we need to amend the docs - and that's
then a change in the documented behaviour.

I do think it's a relatively minor point either way, and practicality
may well imply that we're better avoiding the risk of discovery being
impractical in projects with large directories full of resource files
or similar. But on the expectation side of things, I'd consider the
current behaviour as unexpected.

Paul


More information about the Python-Dev mailing list