Description
Unit tests that assert that an error occurs should check that a specific error is raised.
Like this in Python:
https://github.com/microsoft/LightGBM/blob/6437645c4a0c17046be59e4f57d09952e2e0185f/tests/python_package_test/test_engine.py#L782-L783
And this in R:
https://github.com/microsoft/LightGBM/blob/6437645c4a0c17046be59e4f57d09952e2e0185f/R-package/tests/testthat/test_basic.R#L209-L215
Benefits of this work
- prevents tests from accidentally passing in the presence of an unrelated and unexpected error
Acceptance criteria
- R: every use of
expect_error() and expect_warning() in tests should pass argument regexp to catch a specific error/warning
- Python: every use of
pytest.raises() and pytest.warns() in tests should pass argument match to catch a specific error/warning, and should catch a more specific exception type than "Exception"
Approach
Do not try to fix all of these at once. Pull requests only changing 1 or a small number at a time are preferred.
Python:
R
Notes
How to run the Python tests:
# build lib_lightgbm (just do this once)
cmake -B build -S .
cmake --build build --target _lightgbm -j4
# install Python package (do this every time you change Python code in the library)
sh build-python.sh install --precompile
# run tests
python tests/test_python_package
How to run the R tests:
sh build-cran-package.sh --no-build-vignettes
R CMD INSTALL ./lightgbm*.tar.gz
cd ./R-package/tests
Rscript testthat.R
For other questions on how to set up your development environment, see #6350 (and post questions there about the development process).
Description
Unit tests that assert that an error occurs should check that a specific error is raised.
Like this in Python:
https://github.com/microsoft/LightGBM/blob/6437645c4a0c17046be59e4f57d09952e2e0185f/tests/python_package_test/test_engine.py#L782-L783
And this in R:
https://github.com/microsoft/LightGBM/blob/6437645c4a0c17046be59e4f57d09952e2e0185f/R-package/tests/testthat/test_basic.R#L209-L215
Benefits of this work
Acceptance criteria
expect_error()andexpect_warning()in tests should pass argumentregexpto catch a specific error/warningpytest.raises()andpytest.warns()in tests should pass argumentmatchto catch a specific error/warning, and should catch a more specific exception type than "Exception"Approach
Do not try to fix all of these at once. Pull requests only changing 1 or a small number at a time are preferred.
Python:
test_basictests #6887)test_basictests #6887)test_basictests #6887)test_basictests #6887)test_basicandtest_dasktests #6893)test_basicandtest_dasktests #6893)test_basicandtest_dasktests #6893)test_basicandtest_dasktests #6893)test_dasktests #6955)test_engine#6925)test_engine#6925)test_engine#6925)test_engine#6925)test_engine#6925)test_engine#6926)test_engine#6926)test_engine#6926)test_plotting#6927)test_plotting#6927)test_plotting#6927)test_plotting#6927)test_plotting#6927)test_plotting#6927)test_sklearn#6929)test_sklearn#6929)test_sklearn#6929)R
test_Predictorandtest_dataset#6931)test_Predictorandtest_dataset#6931)test_Predictorandtest_dataset#6931)Notes
How to run the Python tests:
How to run the R tests:
For other questions on how to set up your development environment, see #6350 (and post questions there about the development process).