Python test cases

Python test cases

by sab sab -
Number of replies: 1

Dear Support Team,

I am currently utilizing the Code Runner on Moodle for conducting Python programming exercises. These exercises involve writing codes for specified tasks. For instance, if an exercise requires writing four methods for a given class, I create a test case for each method.

However, I encounter an issue where if an error occurs in one test, the corresponding test case fails to execute or produces an unexpected result. Consequently, subsequent test cases are not evaluated. I have attempted to address this by selecting the "Hide the rest on failure" option, but the issue persists.

Thank you for your assistance.

Best regards,
sea

In reply to sab sab

Re: Python test cases

by Richard Lobb -
If a test gives a runtime error, further testing is aborted. This is by design, to prevent, for example, repeatedly getting timeouts or compile errors on each test.

Usually, the error message issued to the student on the first failure is sufficient for them to correct their code and resubmit. You can adjust the penalty regime to give zero or minimal penalties for the first few submissions if you wish.

If you really wish to continue running tests after a runtime error, you should try to restructure your tests so that runtime errors (or output to the stderr stream which is taken as equivalent to a runtime error) is avoided. You might, for example, want to wrap your test in a try ... except structure, simply printing an error message if the attempt to call the student's method raises an exception.