This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author tpapastylianou
Recipients tpapastylianou
Date 2022-02-04.11:35:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1643974556.47.0.0758530865107.issue46635@roundup.psfhosted.org>
In-reply-to
Content
Back in python 3.6.9, attempting to import __file__ on a namespace package resulted in an attribute error. From at least 3.8 onwards, this behaviour seems to have changed, and __file__ simply returns None instead.

This seems to have broken unittest discovery. Looking at the code, it seems that discover still seems to rely on a try/except block in order to test for a namespace package. Now that the attribute error is no longer present in later python versions, discover simply accepts the None value for __file__, and fails further down the line when attempting to canonicalise a path containing a None value (error effectively expects a string).

On my system with python 3.8, the relevant files/lines are:

- /usr/lib/python3.8/unittest/loader.py()discover()
  The try block starting at line 304 checks for the module's __file__ attribute, expecting to redirect to 307 to "look for namespace packages" in case of an attribute error. Obviously, now that __file__ returns None instead, this logic fails.

- The call to dirname in line 306 therefore proceeds normally, passing a None as a file, which then fails with a TypeError: expected str, bytes or os.PathLike object, not NoneType
 

See https://github.com/tpapastylianou/self-contained-runnable-python-package-template/issues/13# for the example in the wild that prompted the discovery of this bug.
History
Date User Action Args
2022-02-04 11:35:56tpapastylianousetrecipients: + tpapastylianou
2022-02-04 11:35:56tpapastylianousetmessageid: <1643974556.47.0.0758530865107.issue46635@roundup.psfhosted.org>
2022-02-04 11:35:56tpapastylianoulinkissue46635 messages
2022-02-04 11:35:56tpapastylianoucreate