You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Re discussion in #1052, what is the general consensus on testing for exception messages? The way I see it, there are a few ways we can handle this (in order of work required):
Ignore exception messages
Test only for exception messages that are explicitly included in the canonical data for the exercise
When exception messages are not explicitly stated in the canonical data, require that the exercise contributor invent messages for all expected exceptions
Additionally, if we are to test for exception messages at all, we need to have a conventional method of doing so in both Python2 and Python3. assertRaisesRegexp is replaced by assertRaisesRegex in Python3, so as mentioned in #1052 there are a few ways of handling this difference.
Personally I'm not a great fan of requiring particular error messages to be raised by the user. Meaningful messages are great, but exact wording just feels like unnecessary copy-and-pasting to me, and doesn't give the learner the freedom to think about and express what the meaning/source of the error is. This would particularly frustrate me if I thought that the error message was imprecise or I wanted to also display key values.
If we want to test whether people are including messages with their exceptions, we can do a regex for r".+", which would just test that there is something there, and then trust that people will choose to implement something meaningful. I actually quite like this approach, because it actively encourages something which is good practice, without constraining the learner.
If we do implement checks for the presence of error messages, I think we should definitely add something about it to the README insert so that it's clear that we're expecting them (and to encourage people to make them meaningful).
Exception types are controlled by the test-suite, so there's not really much problem on the learner side, but we should try to have some consistency between the test-suites. We could create something along the lines of the Choosing Exceptions to Raise doc pandas has to give everyone something to refer to.
Activity
cmccandless commentedon Oct 30, 2017
Worth noting is that we have a precedent for methods that differ between Python2 and Python3.
N-Parsons commentedon Nov 5, 2017
Personally I'm not a great fan of requiring particular error messages to be raised by the user. Meaningful messages are great, but exact wording just feels like unnecessary copy-and-pasting to me, and doesn't give the learner the freedom to think about and express what the meaning/source of the error is. This would particularly frustrate me if I thought that the error message was imprecise or I wanted to also display key values.
If we want to test whether people are including messages with their exceptions, we can do a regex for
r".+", which would just test that there is something there, and then trust that people will choose to implement something meaningful. I actually quite like this approach, because it actively encourages something which is good practice, without constraining the learner.ilya-khadykin commentedon Nov 7, 2017
Usually, there are two issues:
ValueError(or others for that matter) is raised without any meaningful error message which makes the code less readable and hard to useIf we address this two issues this will be a good enough.
cmccandless commentedon Nov 7, 2017
Sounds like @N-Parsons 's solution of using
r".+"would be adequate for this.This is situational; I don't know that there's a good standardized way to handle this other than
please review.N-Parsons commentedon Nov 8, 2017
If we do implement checks for the presence of error messages, I think we should definitely add something about it to the README insert so that it's clear that we're expecting them (and to encourage people to make them meaningful).
Exception types are controlled by the test-suite, so there's not really much problem on the learner side, but we should try to have some consistency between the test-suites. We could create something along the lines of the Choosing Exceptions to Raise doc
pandashas to give everyone something to refer to.Implement checks for messages being raised with exceptions
Implement checks for messages being raised with exceptions
Implement checks for raising messages with exceptions (#1113)
cmccandless commentedon Nov 27, 2018
For future record, here is the proper way to handle exception testing in this repository:
Edit: if Python 2.7 is no longer supported, the above snippet may be simplified to the following: