Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pytest fails if pyfakefs is installed with "AttributeError: module '_pytest' has no attribute 'pathlib'" #669

Closed
red8888 opened this issue Mar 14, 2022 · 5 comments

Comments

@red8888
Copy link

red8888 commented Mar 14, 2022

Describe the bug
As soon as I install pyfakefs pytest fails with the error: AttributeError: module '_pytest' has no attribute 'pathlib'
This is even before importing and using it.

How To Reproduce
pip install pyfakefs
py.test

Traceback (most recent call last):
  File "/Users/meeee/conda/envs/my-env/bin/py.test", line 11, in <module>
    sys.exit(main())
  File "/Users/meeee/conda/envs/my-env/lib/python3.6/site-packages/_pytest/config/__init__.py", line 58, in main
    config = _prepareconfig(args, plugins)
  File "/Users/meeee/conda/envs/my-env/lib/python3.6/site-packages/_pytest/config/__init__.py", line 185, in _prepareconfig
    pluginmanager=pluginmanager, args=args
  File "/Users/meeee/conda/envs/my-env/lib/python3.6/site-packages/pluggy/_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "/Users/meeee/conda/envs/my-env/lib/python3.6/site-packages/pluggy/_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/Users/meeee/conda/envs/my-env/lib/python3.6/site-packages/pluggy/_callers.py", line 55, in _multicall
    gen.send(outcome)
  File "/Users/meeee/conda/envs/my-env/lib/python3.6/site-packages/_pytest/helpconfig.py", line 89, in pytest_cmdline_parse
    config = outcome.get_result()
  File "/Users/meeee/conda/envs/my-env/lib/python3.6/site-packages/pluggy/_result.py", line 60, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/Users/meeee/conda/envs/my-env/lib/python3.6/site-packages/pluggy/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "/Users/meeee/conda/envs/my-env/lib/python3.6/site-packages/_pytest/config/__init__.py", line 648, in pytest_cmdline_parse
    self.parse(args)
  File "/Users/meeee/conda/envs/my-env/lib/python3.6/site-packages/_pytest/config/__init__.py", line 820, in parse
    self._preparse(args, addopts=addopts)
  File "/Users/meeee/conda/envs/my-env/lib/python3.6/site-packages/_pytest/config/__init__.py", line 772, in _preparse
    self.pluginmanager.load_setuptools_entrypoints("pytest11")
  File "/Users/meeee/conda/envs/my-env/lib/python3.6/site-packages/pluggy/_manager.py", line 287, in load_setuptools_entrypoints
    plugin = ep.load()
  File "/Users/meeee/conda/envs/my-env/lib/python3.6/site-packages/importlib_metadata/__init__.py", line 194, in load
    module = import_module(match.group('module'))
  File "/Users/meeee/conda/envs/my-env/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 656, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 626, in _load_backward_compatible
  File "/Users/meeee/conda/envs/my-env/lib/python3.6/site-packages/_pytest/assertion/rewrite.py", line 290, in load_module
    six.exec_(co, mod.__dict__)
  File "/Users/meeee/conda/envs/my-env/lib/python3.6/site-packages/pyfakefs/pytest_plugin.py", line 19, in <module>
    Patcher.SKIPMODULES.add(_pytest.pathlib)
AttributeError: module '_pytest' has no attribute 'pathlib'

Your environment

Please run the following and paste the output.
Darwin-19.6.0-x86_64-i386-64bit
Python 3.6.15 | packaged by conda-forge | (default, Dec  3 2021, 18:49:43) 
[GCC Clang 11.1.0]
pyfakefs 4.5.5

Why would pyfakefs generate this error even if its not being imported anywhere yet?

@red8888
Copy link
Author

red8888 commented Mar 14, 2022

Downgrading seems to fix it, but I'm testing more.

pip uninstall pyfakefs
pip install pyfakefs==4.5.1
python -c "from pyfakefs.fake_filesystem import __version__; print('pyfakefs', __version__)"

pyfakefs 4.5.1

Running pytest worked

@mrbean-bremen
Copy link
Member

Thanks for the report! That last version contained a fix for pytest 7, which had a change incompatible with the pyfakefs implementation, but it looks like I didn't test older pytest version properly. Which version of pytest have you been using?

I will see if I can fix this later today ot tomorrow.

@mrbean-bremen
Copy link
Member

@red8888 - I added a check for _pytest.pathlib in master,though that that was already added in pytest 3.9.0 - can it be that you have such an old pytest version? Though we claim that we work with pytest 2.8.6 and above, so we should support this. We probably need tests for older pytest versions to ensure this.

Can you please check if pyfakefs master works for you?

@mrbean-bremen
Copy link
Member

If you can confirm that it works for you, I will make a patch release.

@mrbean-bremen
Copy link
Member

Ok, made a new release (including tests with older pytest versions), so I consider this fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants