Skip to content

__spec__ is None inside 'coverage run -m' #838

@RhysU

Description

@RhysU

Describe the bug
Unlike python -m, inside coverage run -m it turns out __spec__ is unexpectedly None.

To Reproduce

$ python --version
Python 3.5.6 :: Anaconda, Inc.

$ coverage --version
Coverage.py, version 4.5.1 with C extension
Documentation at https://coverage.readthedocs.io

$ cat foo.py 
print(__name__)
print(__spec__.name)

$ python -m foo  # Behaves as expected
__main__
foo

$ coverage run -m foo  # Observe __spec__ is None
__main__
Traceback (most recent call last):
  File "/nas/dft/ire/rhys/Build/liquidmetal-debt/foo.py", line 2, in <module>
    print(__spec__.name)
AttributeError: 'NoneType' object has no attribute 'name'
Coverage.py warning: No data was collected. (no-data-collected)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions