Skip to content

Tests: add pytest-based test for rasterExists helper function#7171

Open
ayushjariyal wants to merge 19 commits intoOSGeo:mainfrom
ayushjariyal:pytest_testing
Open

Tests: add pytest-based test for rasterExists helper function#7171
ayushjariyal wants to merge 19 commits intoOSGeo:mainfrom
ayushjariyal:pytest_testing

Conversation

@ayushjariyal
Copy link
Copy Markdown
Contributor

@ayushjariyal ayushjariyal commented Mar 8, 2026

This PR introduces a pytest-based test for rasterExists and a fixture for automatic GRASS session setup.

Changes:

Added assertions.py implementing rasterExists
Added conftest.py with a pytest fixture for GRASS session setup
Added test_assertions.py containing pytest-based tests

Testing:

image

GSoC 2026:

This contribution is a part of GSoC 2026 Support writing tests with pytest project.

@github-actions github-actions bot added Python Related code is in Python libraries tests Related to Test Suite CMake labels Mar 8, 2026
@ayushjariyal
Copy link
Copy Markdown
Contributor Author

@petrasovaa @wenzeslaus

While working on the pytest conversion, I organized the related utilities into a new directory python/grass/pytest to keep the code cleaner and allow easier expansion of pytest-related functionality in the future.

However, the CI checks are currently failing with the following error:

ModuleNotFoundError: No module named 'grass.pytest'

It seems that the new subpackage may not be included in the installed GRASS Python package used in CI.

Before proceeding further, I wanted to confirm whether introducing a separate submodule like grass.pytest is acceptable for the project structure, or if it would be preferable to keep these utilities within the existing grass module.

If the separate submodule approach is acceptable, could you please suggest what changes might be needed so that grass.pytest becomes available during CI builds?

I would like to follow the structure that fits best with the project.

@echoix
Copy link
Copy Markdown
Member

echoix commented Mar 16, 2026

Most probably the makefiles and CMakeLists need to be adjusted in consequence. Look for the closest ones up in the folder hierarchy

@ayushjariyal
Copy link
Copy Markdown
Contributor Author

@echoix, @petrasovaa , Now all the checks are passed. Could you please review it now?

Copy link
Copy Markdown
Member

@wenzeslaus wenzeslaus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a lot of code for what are basically two lines of new code. Yes, something like special set of functions to aid pytest might be needed, but let's think about this first: Raster existence check goes beyond pytest-based testing. Where it can live instead? Can the grass.gunittest code use such a function?

This is also a lot of noise compared to the resulting code. While the current code has some merit, it is nowhere close to being merged.

@ayushjariyal
Copy link
Copy Markdown
Contributor Author

@wenzeslaus , Thanks for the feedback!

I’ve updated the helper to behave as a proper pytest-style assertion by raising AssertionError instead of returning a boolean. I also renamed it to raster_exists to follow snake_case conventions.
Test have been updated to use pytest.raises for failure cases.
Please review and let me know if any changes are needed.

@ayushjariyal ayushjariyal force-pushed the pytest_testing branch 3 times, most recently from e53d8a4 to b9572ad Compare March 19, 2026 07:04
@ayushjariyal ayushjariyal requested a review from wenzeslaus March 19, 2026 09:24
ayushjariyal and others added 12 commits March 19, 2026 23:50
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
ayushjariyal and others added 7 commits March 19, 2026 23:50
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CMake libraries Python Related code is in Python tests Related to Test Suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants