esa / esa/torchquad

Code style in the tests

Open
#144 0 comments 0 reactions 0 assignees View on GitHub
documentation enhancement good first issue help wanted
Dominant language
Python
Stars
230
Forks
47
Avg merge
1d 11h
Merged PRs (30d)
8

Description

It could be possible to change the tests code so that it is easier to read and maintain:
* Currently the tests use `sys.path.append` for the imports instead of importing torchquad, so `__init__.py` is not executed. This also hinders the use of relative imports, e.g. in integration/utils.py.
* It may be possible to shorten the code by replacing the setup_test_for_backend with [parameterized tests](https://docs.pytest.org/en/6.2.x/example/parametrize.html).
* `utils_integration_test.py` shows warnings while the other code uses pytest skips if a backend is not installed. The code could be changed so that pytest skips are used everywhere.

Some of these changes may however make it more difficult to support the execution of the test files with `python3` in addition to `pytest`.

A documentation on how to execute the tests could also be helpful, for example because of GPU out-of-memory problems due to the backend imports:
The test executions on GPU currently may require environment variables which change the memory allocation behaviour of the backends since all backends are imported one after another and some of them can reserve the whole GPU memory.
These environment variables are, for example, `XLA_PYTHON_CLIENT_PREALLOCATE=false`, `TF_FORCE_GPU_ALLOW_GROWTH=true` and `TF_GPU_ALLOCATOR=cuda_malloc_async`. It is also possible to execute the tests on the CPU with `CUDA_VISIBLE_DEVICES=""`.

Contributor guide

Open the contributing guide

Research direction

Review the test imports, integration/utils.py, utils_integration_test.py, and setup_test_for_backend, then compare the current pytest and python3 execution paths. Determine which test-style changes preserve both entry points, replace backend warnings with skips where appropriate, and document the GPU and CPU environment variables needed for reliable test execution.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation, testing
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.