Skip to content

Conversation

@cefect
Copy link

@cefect cefect commented Mar 8, 2025

clarification on adding to the QgsProject

clarification on adding to the QgsProject
@Joonalai
Copy link
Contributor

Joonalai commented Mar 8, 2025

Thank you for the PR and taking an interest in pytest-qgis.

However, your suggested change of adding the layer to project in that particular context shadows the purpose of the example.

If layer is added to the project, it is cleaned automatically. But if it is not, then a separate @clean_qgis_layer is needed (or fixture should have some of the keywords "layer", "lyr", "raster", "rast", "tif" in it's name).

There could definitely be more general examples of how to use the plugin, but I think that the test files of pytest-qgis are good way of getting started.

@cefect
Copy link
Author

cefect commented Mar 8, 2025

Good point, what if we change the example so that "layer" is not included in the name? Which is the main goal of the fixture if I understand

@Joonalai
Copy link
Contributor

Joonalai commented Mar 9, 2025

The name does not contain "layer" it's just "geojson", so no change needed there.

But the examples could still be improved by providing a third example fixture with something like:

# Layer is cleaned automatically since it is added to the project
@pytest.fixture()
def countries() -> QgsVectorLayer:
    layer = QgsVectorLayer("countries.geojson", "countries")
    QgsProject.instance().addMapLayer(layer) 
    return layer

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants