MCPcopy Index your code
hub / github.com/datacamp/pythonwhat / has_no_error

Function has_no_error

pythonwhat/checks/has_funcs.py:748–806  ·  view source on GitHub ↗

Check whether the submission did not generate a runtime error. If all SCTs for an exercise pass, before marking the submission as correct pythonwhat will automatically check whether the student submission generated an error. This means it is not needed to use ``has_no_error()`` explicitly.

(
    state,
    incorrect_msg="Have a look at the console: your code contains an error. Fix it and try again!",
)

Source from the content-addressed store, hash-verified

746
747
748def has_no_error(
749 state,
750 incorrect_msg="Have a look at the console: your code contains an error. Fix it and try again!",
751):
752 """Check whether the submission did not generate a runtime error.
753
754 If all SCTs for an exercise pass, before marking the submission as correct pythonwhat will automatically check whether
755 the student submission generated an error. This means it is not needed to use ``has_no_error()`` explicitly.
756
757 However, in some cases, using ``has_no_error()`` explicitly somewhere throughout your SCT execution can be helpful:
758
759 - If you want to make sure people didn't write typos when writing a long function name.
760 - If you want to first verify whether a function actually runs, before checking whether the arguments were specified correctly.
761 - More generally, if, because of the content, it's instrumental that the script runs without
762 errors before doing any other verifications.
763
764 Args:
765 incorrect_msg: if specified, this overrides the default message if the student code generated an error.
766
767 :Example:
768
769 Suppose you're verifying an exercise about model training and validation: ::
770
771 # pre exercise code
772 import numpy as np
773 from sklearn.model_selection import train_test_split
774 from sklearn import datasets
775 from sklearn import svm
776
777 iris = datasets.load_iris()
778 iris.data.shape, iris.target.shape
779
780 # solution
781 X_train, X_test, y_train, y_test = train_test_split(
782 iris.data, iris.target, test_size=0.4, random_state=0)
783
784 If you want to make sure that ``train_test_split()`` ran without errors,
785 which would check if the student typed the function without typos and used
786 sensical arguments, you could use the following SCT: ::
787
788 Ex().has_no_error()
789 Ex().check_function('sklearn.model_selection.train_test_split').multi(
790 check_args(['arrays', 0]).has_equal_value(),
791 check_args(['arrays', 0]).has_equal_value(),
792 check_args(['options', 'test_size']).has_equal_value(),
793 check_args(['options', 'random_state']).has_equal_value()
794 )
795
796 If, on the other hand, you want to fall back onto pythonwhat's built in behavior,
797 that checks for an error before marking the exercise as correct, you can simply
798 leave of the ``has_no_error()`` step.
799
800 """
801 state.assert_execution_root("has_no_error")
802
803 if state.reporter.errors:
804 state.report(incorrect_msg, {"error": str(state.reporter.errors[0])})
805

Callers

nothing calls this directly

Calls 1

assert_execution_rootMethod · 0.80

Tested by

no test coverage detected