<div dir="ltr"><div dir="ltr"></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, 15 Apr 2022 at 03:49, Adithya Ambapurkar <<a href="mailto:adinayyu@gmail.com" target="_blank">adinayyu@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">I have selected test_gunittest_doctests.py file</div></blockquote><div><br></div><div>Perhaps try something else. This one may have additional challenges because it is doctest. Although it actually runs for me in Binder without errors.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"> and tried to run on jupyterlab on binder. I included the necessary grass code and when i run it gives some error </div></blockquote><div><br></div><div>There is more than one way to do it, but given what you tried, the best way to do it for you is to in a notebook:</div></div><div class="gmail_quote"><br></div><div class="gmail_quote">```<br></div><div class="gmail_quote"></div><div class="gmail_quote"># Import Python standard library we need.<br>import os<br>import sys<br>import subprocess<br><br># Ask GRASS GIS where its Python packages are.<br>sys.path.append(<br>    subprocess.check_output(["grass", "--config", "python_path"], text=True).strip()<br>)<br><br></div><div class="gmail_quote"># Run the tests.</div><div class="gmail_quote"># (The path is where the source code (with tests) is. In Binder, the source code is in the user's home directory.)<br></div><div class="gmail_quote">os.chdir(os.path.expanduser("~"))<br>!python -m grass.gunittest.main --location nc_basic_spm_grass7 --location-type nc<div>```<br></div><div><br></div><div>The above works for me in a notebook in Binder and it should work locally as well.<br></div><div><br></div><div>Alternatively, in Binder, you can also use the Terminal (File > New Launcher > Terminal) and use `grass` command with --exec instead of the above Python notebook code. That's what I usually use locally in the terminal on Ubuntu. An example of the that is here:<br></div><div><br></div><div><a href="https://github.com/OSGeo/grass/blob/main/.github/workflows/test_thorough.sh" target="_blank">https://github.com/OSGeo/grass/blob/main/.github/workflows/test_thorough.sh</a></div><div><br></div><div>The doc for running tests in general is here:<br></div><div><br></div><div><a href="https://grass.osgeo.org/grass80/manuals/libpython/gunittest_running_tests.html" target="_blank">https://grass.osgeo.org/grass80/manuals/libpython/gunittest_running_tests.html</a></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Without the grass code if i run nothing happens<br></div></div></blockquote><div><br></div><div>Not sure what you mean, but I get an error with your notebook. Anyway, I suggest <i>not</i> to run it this way, although you could make it work by adding %%python (cell magic) at the top of the cell. Then it works, runs tests, and they pass. I didn't investigate that further. I didn't think of this as an experimental method before, but probably not a good way of running tests in general.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><div>I also tried to run locally and installed grass, pytest, ipython packages using pip but it gives grass.gunittest module not found error</div></div></div></blockquote><div><br></div><div>Running pytest should not give you "grass.gunittest not found" because grass.gunittest is not used when running pytest. (Note that you need the latest code from the main branch to run pytest otherwise pytest will fail with lots of errors.)</div><div><br></div><div>Anyway, the important step likely missing is that you need to add GRASS Python packages on path.<br></div><div><br></div><div>I run pytest on Ubuntu with the following:<br></div><div><br></div><div>PYTHONPATH=`grass --config python_path`:$PYTHONPATH LD_LIBRARY_PATH=/path/to/compiled/grass/dist.x86_64-pc-linux-gnu/lib pytest /test/file/to/run/name.py -vv</div><div><br></div><div>Or, in multiple steps:</div><div><br></div><div>export PYTHONPATH=`grass --config python_path`:$PYTHONPATH</div><div>export LD_LIBRARY_PATH=/path/to/compiled/grass/dist.x86_64-pc-linux-gnu/lib</div><div>pytest /test/file/to/run/name.py -vv</div><div><br></div><div>You can see another example in the pytest.yml workflow for GitHub Actions:</div><div><br></div><div><a href="https://github.com/OSGeo/grass/blob/main/.github/workflows/pytest.yml">https://github.com/OSGeo/grass/blob/main/.github/workflows/pytest.yml</a></div><div><br></div><div></div></div></div>