To test for a specific exception in unit testing, use pytest.raises.
pytest.raises
For example, you can use it to test if a ValueError is thrown when there are NaN values in the group column.
ValueError