spec is None inside 'coverage run -m' · Issue #838 · nedbat/coveragepy (original) (raw)
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)