Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grass.script: Reduce use of env in create_location #3428

Merged

Conversation

wenzeslaus
Copy link
Member

  • Reduces use of runtime environment in the create_location function (gisenv call removed).
  • Reduces scope of gisrc which simplifies cleanup.
  • Adds 4 tests for basic creation of the location (project).

* Reduces use of runtime environment in the create_location function (gisenv call removed).
* Reduces scope of gisrc which simplifies cleanup.
* Adds 4 tests for basic creation of the location (project).
@wenzeslaus wenzeslaus added this to the 8.4.0 milestone Feb 16, 2024
@wenzeslaus wenzeslaus self-assigned this Feb 16, 2024
@github-actions github-actions bot added Python Related code is in Python libraries labels Feb 16, 2024
@wenzeslaus wenzeslaus enabled auto-merge (squash) February 16, 2024 15:05
@wenzeslaus
Copy link
Member Author

@echoix Only tangentially related to this PR: You may be interested to know that these tests can't run in parallel and that there are other tests like that. The thing is that the only way to set up the runtime environment with location (project) connection is to change the global process state (environmental variables). However, we are moving the API towards a more robust approach, so the limitation will hopefully disappear. Notably, this is about pytest-based tests. The grass.gunitest tests can be highly parallelized. We can have a deeper discussion on the mailing list or in Discussions if you want.

@wenzeslaus wenzeslaus merged commit 7df156f into OSGeo:main Feb 16, 2024
25 checks passed
@wenzeslaus wenzeslaus deleted the simplify-environment-creation-add-tests branch February 16, 2024 16:12
@echoix
Copy link
Member

echoix commented Feb 17, 2024

@wenzeslaus

@echoix Only tangentially related to this PR: You may be interested to know that these tests can't run in parallel and that there are other tests like that. The thing is that the only way to set up the runtime environment with location (project) connection is to change the global process state (environmental variables). However, we are moving the API towards a more robust approach, so the limitation will hopefully disappear. Notably, this is about pytest-based tests. The grass.gunitest tests can be highly parallelized. We can have a deeper discussion on the mailing list or in Discussions if you want.

You might be interested in monkeypatch of pytest:
https://docs.pytest.org/en/latest/how-to/monkeypatch.html
https://docs.pytest.org/en/latest/how-to/monkeypatch.html#monkeypatching-environment-variables
https://dev.to/mhihasan/testing-environment-variable-in-pytest-38ec

Sometimes tests need to invoke functionality which depends on global settings or which invokes code which cannot be easily tested such as network access. The monkeypatch fixture helps you to safely set/delete an attribute, dictionary item or environment variable, or to modify sys.path for importing.
...
All modifications will be undone after the requesting test function or fixture has finished. The raising parameter determines if a KeyError or AttributeError will be raised if the target of the set/deletion operation does not exist.
...
3. Modifying environment variables for a test e.g. to test program behavior if an environment variable is missing, or to set multiple values to a known variable. monkeypatch.setenv and monkeypatch.delenv can be used for these patches.
4. Use monkeypatch.setenv("PATH", value, prepend=os.pathsep) to modify $PATH, and monkeypatch.chdir to change the context of the current working directory during a test.

jadenabrams100 pushed a commit to ncsu-csc472-spring2024/grass-CI-playground that referenced this pull request Feb 21, 2024
* Reduces use of runtime environment in the create_location function (gisenv call removed).
* Reduces scope of gisrc which simplifies cleanup.
* Adds 4 tests for basic creation of the location (project).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libraries Python Related code is in Python
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants