Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ latex/
lib/*/html/
lib/*/latex/

# Ignore build environment file for local test runs (see AGENTS.md)
.grass_build_env

# Ignore code coverage files
*.gcov
*.gcno
Expand Down
41 changes: 25 additions & 16 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,38 +62,47 @@ and test dependencies (pytest, numpy, etc.) installed in the Python
environment. If using a virtual environment (venv, conda, pipenv, etc.),
it likely needs to be activated before running tests.

If running from a local build (not a system install), add the binary directory
to PATH first:
If running from a local build (not a system install), generate a build
environment file once per build. This resolves all dynamic paths up front
so that subsequent test commands need no command substitution:

```bash
export PATH="$(pwd)/bin.$(uname -m)-pc-linux-gnu:${PATH}"
cat > .grass_build_env << EOF
export PATH="$(pwd)/bin.$(uname -m)-pc-linux-gnu:\${PATH}"
export PYTHONPATH="$(grass --config python_path):\${PYTHONPATH}"
export LD_LIBRARY_PATH="$(grass --config path)/lib:\${LD_LIBRARY_PATH}"
EOF
```

Before running pytest, set the required environment variables:
Regenerate the file after rebuilding GRASS or switching branches. The file
is local and should not be committed (it is listed in `.gitignore`).
The exact content of the generated file above is a best guess for most
Linux setups. Adapt it as needed for the local environment — for example,
the architecture suffix, the virtual environment wrapper, or additional
variables may differ.

```bash
export PYTHONPATH="$(grass --config python_path):${PYTHONPATH}"
export LD_LIBRARY_PATH="$(grass --config path)/lib:${LD_LIBRARY_PATH}"
```
Then prefix each pytest invocation with `source .grass_build_env`:

For coverage reporting, two additional variables are needed (used by
`.coveragerc` to map paths):
**Run tests for a specific tool:**

```bash
export INITIAL_GISBASE="$(grass --config path)"
export INITIAL_PWD="${PWD}"
source .grass_build_env && pytest raster/r.slope.aspect/tests/
```

**Run tests for a specific tool:**
**Run a single test file:**

```bash
pytest raster/r.slope.aspect/tests/
source .grass_build_env && pytest raster/r.slope.aspect/tests/r_slope_aspect_test.py
```

**Run a single test file:**
For coverage reporting, two additional variables are needed (used by
`.coveragerc` to map paths). Add them to the env file:

```bash
pytest raster/r.slope.aspect/tests/r_slope_aspect_test.py
cat >> .grass_build_env << EOF
export INITIAL_GISBASE="$(grass --config path)"
export INITIAL_PWD="${PWD}"
EOF
```

**Run gunittest-style tests** (legacy `testsuite/` directories; currently the
Expand Down
Loading