On Fri, 15 Apr 2022 at 03:49, Adithya Ambapurkar <adina...@gmail.com> wrote:
> I have selected test_gunittest_doctests.py file > Perhaps try something else. This one may have additional challenges because it is doctest. Although it actually runs for me in Binder without errors. > and tried to run on jupyterlab on binder. I included the necessary grass > code and when i run it gives some error > 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: ``` # Import Python standard library we need. import os import sys import subprocess # Ask GRASS GIS where its Python packages are. sys.path.append( subprocess.check_output(["grass", "--config", "python_path"], text=True).strip() ) # Run the tests. # (The path is where the source code (with tests) is. In Binder, the source code is in the user's home directory.) os.chdir(os.path.expanduser("~")) !python -m grass.gunittest.main --location nc_basic_spm_grass7 --location-type nc ``` The above works for me in a notebook in Binder and it should work locally as well. 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: https://github.com/OSGeo/grass/blob/main/.github/workflows/test_thorough.sh The doc for running tests in general is here: https://grass.osgeo.org/grass80/manuals/libpython/gunittest_running_tests.html > Without the grass code if i run nothing happens > Not sure what you mean, but I get an error with your notebook. Anyway, I suggest *not* 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. > I also tried to run locally and installed grass, pytest, ipython packages > using pip but it gives grass.gunittest module not found error > 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.) Anyway, the important step likely missing is that you need to add GRASS Python packages on path. I run pytest on Ubuntu with the following: 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 Or, in multiple steps: export PYTHONPATH=`grass --config python_path`:$PYTHONPATH export LD_LIBRARY_PATH=/path/to/compiled/grass/dist.x86_64-pc-linux-gnu/lib pytest /test/file/to/run/name.py -vv You can see another example in the pytest.yml workflow for GitHub Actions: https://github.com/OSGeo/grass/blob/main/.github/workflows/pytest.yml
_______________________________________________ grass-dev mailing list grass-dev@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/grass-dev