Python Assertion Error Help

  • #1
59
4
1581924271419.png

I would like to make output only read:

Traceback (most recent call last):
AssertionError

... without giving the File "<input>", line 1, in <module>
 

Answers and Replies

  • #3
Why? The line number is there to help you debug your code. If this is to show a message to an end user then you should be using try...except, not just letting the program fail.
 
  • #4
Oh its for unit testing? You should use assertRaises in your test instead of testing the crash dump output.
 
  • #5
Oh its for unit testing? You should use assertRaises in your test instead of testing the crash dump output.
can you tell me what assertRaises exactly do and how to use it? I have never heard about it :(
 
  • #6
Hmmm, looking again I am not sure you are using a unit test framework. Is this an online tutorial? If so, stick with my first answer: catch the assertion and print its message. You can look up how to catch the failing assertion with try...except and how to get the message string from an AssertionError in a Python reference if you haven't covered them already (have you skipped some of the tutorial?).
 

Suggested for: Python Assertion Error Help

Replies
3
Views
194
Replies
2
Views
106
Replies
6
Views
281
Replies
6
Views
699
Replies
1
Views
927
Replies
4
Views
678
Replies
18
Views
663
Back
Top