Running pycharm pytest with pluggy hooks Follow
I have a command line tool that uses pluggy hooks and the setuptools `develop` enviornment. So in my virtual environment, I ran `python setup.py develop` and the hooks work as expected. If I run pytest from the console, everything works fine as well.
However, if I run the same tests from PyCharm, I get an error at `self.pluggy_manager.load_setuptools_entrypoints("MyApp")`. Likewise, when I execute any functions from pycharm that eventually use the hook I get the same error:
File "...\.venv38\lib\site-packages\pluggy\_manager.py", line 287, in load_setuptools_entrypoints
plugin = ep.load()
File "C:\Users\...\AppData\Local\Programs\Python\Python38\lib\importlib\metadata.py", line 77, in load
module = import_module(match.group('module'))
File "C:\Users\...\AppData\Local\Programs\Python\Python38\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 848, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "...\hooks\printer.py", line 22, in <module>
AttributeError: module 'MyApp' has no attribute 'hookimpl'
Since it works as intended when executed in the venv from command line (or from the PyCharm terminal), I assume that PyCharm is not recognizing the develop environment and its installed entrypoints when running pytest or the code in general. What can I do to change that? I know that the run configuration can be edited but I have no idea where to start when it comes to this problem
Please sign in to leave a comment.
in the meantime I figured out a solution for my issue. In my project we are "faking" a shared namespace in multiple different folders. So we have multiple different folders, each with a folder called "MyApp" in which an the sys path is extended in the init file so that all modules can be accessed from each other.
Path extension by:
The pluggy hookimpl was defined in one of these init files. However, when loading it PyCharm does not check the full path apparently but only the latest added (I guess) where the hookimpl is not defined. I have since moved the hookimpl to a more precise location and it works without issues.
Could you please provide the following:
- The command used to run the test from the terminal
- Screenshot of your run/debug configuration to run the same test
- The outputs of the diagnostic script from both the terminal and PyCharm