GispoCoding / pytest-qgis

A pytest plugin for testing QGIS python plugins
GNU General Public License v2.0
29 stars 8 forks source link

Allow changing the map extent properly when showing the map #62

Closed Joonalai closed 2 months ago

Joonalai commented 3 months ago

This PR fixes a bug where adding map layer causes the map to zoom to its whole extent even though the extent is changed after adding the layer.

This should be merged after #60 (CI changes) and added to the upcoming release.

Joonalai commented 3 months ago

@LKajan could you please review this? This should be added to the upcoming release as well.

Joonalai commented 3 months ago

Thinking about this further, I realized that this also changes the behavior of the program tested. Which can lead to false test results when it runs differently during tests and real execution.

The thing is that it really doesn't change the behavior. In QGIS the events are processed all the time but in test this is not the case. I think it definitely is more intuitive that the plugin behaves more like QGIS than not.

Do you think it work to create for example a method like:

def set_extent_after_events_processed(extent):
    _APP.processEvents()
    canvas.setExtent(extent)

and call it in test methods if the extent is to be changed?

I don't really think this is a good idea since the main idea of the plugin is to act in the background and let the user use PyQGIS API to run QGIS code in tests. What if the extent is changed in code rather than in test? Should user mock the canvas.setExtent to call this function instead?

Joonalai commented 2 months ago

@LKajan, @ismogis what do you think, is there room for improvement or should this be merged?