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

Can't use addToolBar with qgis_iface #19

Closed
jmkerloch opened this issue Feb 8, 2022 · 5 comments · Fixed by #23
Closed

Can't use addToolBar with qgis_iface #19

jmkerloch opened this issue Feb 8, 2022 · 5 comments · Fixed by #23
Labels
bug Something isn't working

Comments

@jmkerloch
Copy link

Describe the bug
I'm using qgis_iface fixture to initialize my plugin

def test_1loadplugin(qgis_app, qgis_iface):
    qgis_app.initQgis()
    plugin = Plugin(qgis_iface)
    plugin.initGui()

But when I add a toolbar with my plugin I get this error

self = <pytest_qgis.qgis_interface.QgisInterface object at 0x7f0ac330ddc0>, name = <PyQt5.QtWidgets.QToolBar object at 0x7f0b3344faf0>

    def addToolBar(self, name: str) -> QToolBar:
        """Add toolbar with specified name.
    
        :param name: Name for the toolbar.
        :type name: str
        """
>       toolbar = QToolBar(name, parent=self._mainWindow)
E       TypeError: 'parent' is an unknown keyword argument

To Reproduce
Steps to reproduce the behavior:

  1. Create a plugin with toolbar add

self.iface.addToolBar(self.new_toolbar)

  1. Create a pytest with pytest-qgis plugin use and plugin initialization

Expected behavior
qgis_iface fixture should allow mocking of toolbar add.

Environment (please complete the following information):

  • OS: [Ubuntu 21.10]
  • Python: [3.9]

Additional context
I have upgraded my pytest-qgis installation with new version 1.3.0

@jmkerloch jmkerloch added the bug Something isn't working label Feb 8, 2022
@JaumeFigueras
Copy link
Contributor

Hi,
I ran into the same problem, but with @Joonalai help we solved it.
I do not initialize plugins the way you exemplified. I run the same procedure as QGIS does, calling qgis.util functions. You can check my code at https://github.com/JaumeFigueras/GisFIRE-SpreadSimulation/tree/master/test It is "tuned" to my config of multiple plugins but I think is easy enough to understand. Check the test and the two fixtures I wrote.
Hope this helps.

@Joonalai
Copy link
Contributor

Joonalai commented Feb 10, 2022

Thank you for the issue! It seems that the addToolBar method of QgisInterface supports also QToolBar objects as first argument. The stub implementation should be fixed to take this into account.

@Joonalai
Copy link
Contributor

As a side note, you don't have to initialize QGIS, since it is done automatically.

def test_1loadplugin(qgis_app, qgis_iface):
    qgis_app.initQgis()
    plugin = Plugin(qgis_iface)
    plugin.initGui()

@vicente23
Copy link

Hi,

I encountered the same problem when I upgraded pytest-qgis to the version 1.3.0.

The problem was not present in version 1.2.0.

@Joonalai
Copy link
Contributor

Thank you for letting me know, I will fix this ASAP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants