-
Notifications
You must be signed in to change notification settings - Fork 8
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
qgis.utils iface isn't being replaced #35
Comments
Thank you for the issue and for using pytest-qgis! I think that what is happening here is that you are importing the module that has Here are a example of the problem: module_a.py: from qgis.utils import iface
class Myclass:
... conftest.py: from module_a import MyClass # This line causes the iface not to be patched in this module
@pytest.fixture()
def my_class():
return MyClass()
... Solution is to import module_a in a fixture: conftest.py: @pytest.fixture()
def my_class():
from module_a import MyClass # Now iface is already patched by the pytest_configure hook of pytest-qgis
return MyClass()
... Hopefully this helps. |
Thanks for quick reply! I’ll give this a shot tomorrow and let you know if it resolves my issue. |
On another note, I was recently using the pytest-qt module to simulate mouse clicks on a QComboBox in my plugin. I was trying to use their qtbot’s keyClicks to try and change the combo box text. For some reason, this seems to work 50% of the time. I have 4 items in my combo box (aspen, bot, bot_train, bot_test) and for some reason the combo box text changes for aspen and bot but not for bot_train and bot_test. I have never seen the combo box fail to switch when I use the plugin myself; this seems to only occur in the test environment. I saw that you guys have a qgis_bot fixture, but it doesn’t seem to have this keyClicks attribute. Should I be using this module instead, and if so, how should I be using it? Any advice would be appreciated! This might be a pytest-qt problem, but I figured I should ask here since I am testing a qgis plugin. |
Edit: replied to the new issue. |
Hi, pytest-qt maintainer here.
In general, prefer to interact with widgets using their direct methods, rather than QtBot's: calling I realize our documentation needs to be updated on that recommendation (EDIT: pytest-dev/pytest-qt#493). |
Thanks for all the help! |
Great to hear! I added commit to mention about the issue in the PR #34. |
I have created a plugin using qgis 3.28.4. My plugin occasionally will make the following call
from qgis.utils import iface
. In the testing docker container, the iface imported from qgis.utils is None, rather than an actual iface object.In your README, it claims that
pytest_configure hook is used to initialize and configure [QgsApplication](https://qgis.org/pyqgis/master/core/QgsApplication.html). With QGIS >= 3.18 it is also used to patch qgis.utils.iface with qgis_iface automatically.
However, that doesn't seem to be the case.Am I supposed to be using this
pytest_configure
somewhere in my test case or in my conftest.py file?Thanks
The text was updated successfully, but these errors were encountered: