python 3.7: coverage fails with TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType
See original GitHub issueINTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "/home/olli/.pyenv/versions/3.7.0/envs/foobar/lib/python3.7/site-packages/_pytest/main.py", line 178, in wrap_session
INTERNALERROR> session.exitstatus = doit(config, session) or 0
INTERNALERROR> File "/home/olli/.pyenv/versions/3.7.0/envs/foobar/lib/python3.7/site-packages/_pytest/main.py", line 215, in _main
INTERNALERROR> config.hook.pytest_runtestloop(session=session)
INTERNALERROR> File "/home/olli/.pyenv/versions/3.7.0/envs/foobar/lib/python3.7/site-packages/pluggy/hooks.py", line 258, in __call__
INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR> File "/home/olli/.pyenv/versions/3.7.0/envs/foobar/lib/python3.7/site-packages/pluggy/manager.py", line 67, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/home/olli/.pyenv/versions/3.7.0/envs/foobar/lib/python3.7/site-packages/pluggy/manager.py", line 61, in <lambda>
INTERNALERROR> firstresult=hook.spec_opts.get('firstresult'),
INTERNALERROR> File "/home/olli/.pyenv/versions/3.7.0/envs/foobar/lib/python3.7/site-packages/pluggy/callers.py", line 196, in _multicall
INTERNALERROR> gen.send(outcome)
INTERNALERROR> File "/home/olli/.pyenv/versions/3.7.0/envs/foobar/lib/python3.7/site-packages/pytest_cov/plugin.py", line 228, in pytest_runtestloop
INTERNALERROR> self.cov_controller.finish()
INTERNALERROR> File "/home/olli/.pyenv/versions/3.7.0/envs/foobar/lib/python3.7/site-packages/pytest_cov/engine.py", line 167, in finish
INTERNALERROR> self.cov.stop()
INTERNALERROR> File "/home/olli/.pyenv/versions/3.7.0/envs/foobar/lib/python3.7/site-packages/coverage/control.py", line 781, in save
INTERNALERROR> self.get_data()
INTERNALERROR> File "/home/olli/.pyenv/versions/3.7.0/envs/foobar/lib/python3.7/site-packages/coverage/control.py", line 834, in get_data
INTERNALERROR> self._post_save_work()
INTERNALERROR> File "/home/olli/.pyenv/versions/3.7.0/envs/foobar/lib/python3.7/site-packages/coverage/control.py", line 849, in _post_save_work
INTERNALERROR> self._warn_about_unmeasured_code(pkg)
INTERNALERROR> File "/home/olli/.pyenv/versions/3.7.0/envs/foobar/lib/python3.7/site-packages/coverage/control.py", line 882, in _warn_about_unmeasured_code
INTERNALERROR> has_file = hasattr(mod, '__file__') and os.path.exists(mod.__file__)
INTERNALERROR> File "/home/olli/.pyenv/versions/3.7.0/lib/python3.7/genericpath.py", line 19, in exists
INTERNALERROR> os.stat(path)
INTERNALERROR> TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType
In Python 3.7 namespace packages seem to have a __file__ == None
attribute, which leads to coverage not recognizing it.
https://github.com/nedbat/coveragepy/blob/coverage-4.5.1x/coverage/control.py#L881
# ipython
Python 3.7.0 (default, Jul 1 2018, 11:34:46)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.5.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import com
In [2]: vars(com)
Out[2]:
{'__name__': 'com',
'__doc__': None,
'__package__': 'com',
'__loader__': <_frozen_importlib_external._NamespaceLoader at 0x7f2944081588>,
'__spec__': ModuleSpec(name='com', loader=<_frozen_importlib_external._NamespaceLoader object at 0x7f2944081588>, submodule_search_locations=_NamespacePath(['/home/code/ml/cookiecutter/foobar/src/com', '/home/olli/.pyenv/versions/3.7.0/envs/foobar/lib/python3.7/site-packages/com'])),
'__file__': None,
'__path__': _NamespacePath(['/home/code/ml/cookiecutter/foobar/src/com', '/home/olli/.pyenv/versions/3.7.0/envs/foobar/lib/python3.7/site-packages/com'])}
In [3]:
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
stat: path should be string, bytes, os.PathLike or integer, not ...
I am using Python 3.7.2 and it is 64 bits. Here is full Traceback of error: Traceback (most recent call last): File "refext.py ......
Read more >Backup Error: TypeError: stat: path should be string, bytes, os ...
PathLike or integer, not NoneType. Is anyone getting this error on Dropbox or Amazon S3? This started two days ago and i can't...
Read more >Typeerror: Stat: Path Should Be String, Bytes, Os.Pathlike Or ...
On Career Karma learn about the Python typeerror: not all arguments converted during string formatting error how the error works. TypeError: stat: path...
Read more >2022-January.txt - Python mailing list
That's not a lot of code but I feel like pathlib should have higher-level abstractions for all path-related functionality of os.
Read more >mechanicalsoup is not redirecting to where it should redirect to
csv file from URL into Python 3.x - _csv.Error: iterator should return strings, not bytes (did you open the file in text mode?)...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
And it turns out this has already been fixed, in c9f4f661ccb7decb55055d80a1e9a1cbb825b27f
Something like this:
In my original scenario one dependency provides a part of the namespace and I call coverage via
pytest --cov com
to get the error, but this does not work in this simple case (who knows)…