GRASS GSoC 2026 Support writing tests with pytest

From GRASS-Wiki
Revision as of 03:28, 5 May 2026 by Gulshan (talk | contribs) (mentor name change)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Student Name Gulshan Kumar
Organization NumFOCUS
Mentor Name Vaclav Petras, Corey White
GitHub Fork View Repo
LinkedIn Profile View LinkedIn

Abstract

The current test framework in GRASS, gunittest, was designed before GitHub era. Based on Python unittest, it has several distinct types of assertion methods and requires tests to be executed from within a GRASS shell session. This has steep learning curve and is far from modern testing methods which uses Pytest.

This project aims to modify the GRASS test by shifting the testing framework to pytest. Pytest uses simple and plain assert statements, fixtures, and is more readable. The project will involve designing a new API for several grass related assertions, implementing fixtures to handle GRASS sessions and temporary mapsets outside of the GRASS shell, integrating sample datasets, and iterative refactoring (utilizing tools like Bowler) to migrate existing tests. Thus, this will result in a more Pythonic, accessible, and maintainable testing environment for GRASS contributors.

Project Scope

  1. API Design: Designing how GRASS specific assertions (like rasterExists) will look in pytest. We will draw inspiration from NumPy/GDAL own migration history.
  2. Session & Mapset Fixtures: Designing pytest fixtures to handle GRASS session setup and teardown. This also include running pytest outside of a GRASS session.
  3. Isolation: Tests must be isolated to ensure there is no side effects between them. We will decide on per file/per function isolation.
  4. Sample Dataset Integration: Addressing the dependency on the NC SPM sample dataset from grass.gunittest to the pytest framework.
  5. Iterative Refactoring Strategy: Defining the location for the new tests (tests or testsuite directories) and utilizing AST-based refactoring tools like Bowler (combined with AI agents) to automate the migration of existing tests.
  6. Contributor Documentation: Creating a user friendly testing guide for future contributors to encourage rapid adoption of the new pytest framework.

Timeline

Period Timeline Tasks Status
Community Bonding Period

May 1 - May 24, 2026

  1. Finalize the API design for the new assertion functions alongside mentors.
  2. Research NumPy and GDAL transition to pytest for more insights.
  3. Engage with the community to establish conventions for the new tests structure.
Official Coding Period
Week 1 (May 25 - May 31)
  1. Implement fixtures to allow pytest execution outside the GRASS shell in conftest.py.
  2. Fix grass.script.setup.init behavior.
Week 2 (June 1 - June 7)
  1. Implement function/module scoped fixtures for temporary mapset creation and teardown. Ensure environment isolation.
Week 3 (June 8 - June 14)
  1. Begin translating basic gunittest assertions to pytest equivalents.
Week 4 (June 15 - June 21)
  1. Implement complex geospatial comparison functions (e.g., vector/raster fitting).
Week 5 (June 22 - June 28)
  1. Work on integrating the NC SPM sample dataset into the new pytest architecture.
Week 6 (June 29 - July 5)
  1. Finalize dataset integration.
  2. Write unit tests for the new pytest fixtures and utilities to ensure framework stability.
Midterm Evaluation (July 6 - July 10)
  1. Submit MidTerm evaluation.
Week 7 (July 6 - July 12)
  1. Develop automation scripts using Bowler (and AI assistance) for iterative refactoring of existing test suites.
Week 8 (July 13 - July 19)
  1. Begin migrating test files from unittest to pytest.
  2. Decide on unittest class structures vs. pure functions based on mentor feedback.
Week 9 (July 20 - July 26)
  1. Continue iterative migration, focusing on tests that failed or interacted poorly with grass --exec.
Week 10 (July 27 - August 2)
  1. Draft the User Guide for contributors on how to write tests using the new pytest framework.
Week 11 (August 3 - August 9)
  1. Address edge cases, fix failing tests resulting from the migration, and ensure CI pipelines are green.
Week 12 (August 10 - August 16)
  1. Buffer week. Code cleanup, finalizing PRs, and reviewing documentation.
Final Week August 17 - August 24
  1. Submit Report, Project, Blog and Documentation


Reports

Community Bonding Period

Log of Pull Requests

PR PR Title
#7071 g.parser: Missing support G_OPT_F FORMAT in python %option
#7051 t.vect.list: Added support for JSON, YAML and CSV
#7004 grass.jupyter: use json output format in timeseriesmap
#6971 db.columns: added format list and format=csV
#6933 db.columns: added support for -e to print more column information
#6867 v.info: Add format csv with c flag and sync with v.db.connect
#6823 v.info: Sync -c flag with format=JSON output with v.db.connect
#6801 v.db.connect: Ends with error if both -p and -c flags are present
#6728 db.select: Adding JSON and CSV support
#6703 doc: Enable MathJax rendering for equations in MkDocs documentation