Force a unit test case to ERROR in Python

Sanket

I went through the Unit Test Case module of python and found that there is way to force a test case to fail using the TestCase.fail() object. However I did not find anything that would force a test case to error. Any ideas on how this could be done?

EDIT:

More explaination

There are few test scripts which were written long ago and which I'm using right now for testing a firmware. These test scripts use the UnitTest module of python. The test scripts also import a bunch of other user-written modules. All these user written modules throw few exceptions. So whenever a test case doesn't call methods from user-written modules with correct inputs exception are thrown. the UnitTest module rightly flags all such test cases as errors. But by looking at the output of UnitTest module, which is just a Traceback to the line where exception was generated, it is not immediately clear to me because of which input the exception was generated. So I used try-except construct in the test scripts to catch the exceptions and print out the input which was the reason for exception. But since I handled the exceptions UnitTest was flagging these test cases as pass. Using the raise statement in the except block, as pointed out by @alecxe, solved this issue.

alecxe

Just use raise to raise an exception:

raise Exception('Manually raised exception')

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Force a yielded function to error for unit test

From Dev

write unit test case in python for below algorithm

From Dev

Unit Test case using Assert

From Dev

Unit test case for html element

From Dev

Unit test an edge case with Junit

From Dev

OCMock unit test error

From Dev

Python unit test failure: should raise value error but not

From Dev

Unit test Theories in Python?

From Java

Error when running unit tests in visual studio: Test-case objects missing

From Dev

How to write unit test case for BadRequest?

From Dev

Unit test case view controller crash swift

From Dev

Unit test case for call back methods ios

From Dev

Jasmine unit test case for $routeChangeStart in AngularJS

From Dev

Null @Autowired beans in unit test case

From Dev

Scala : How to create Unit test case in Intellij

From Dev

Mocking Network response for unit test case

From Dev

Controllers are not defined in karma unit test case

From Dev

Unit Test case in Grails with mocking the methods

From Dev

How to fix the unit test issue in my case?

From Dev

How to cover setInterval in the unit test case in javascript

From Dev

Python Unit-Testing: In Nose is there a way to skip a test case from nose.run()?

From Dev

AngularJS Unit Test Error dependence

From Dev

VSTS Unit test error message

From Dev

Error in test method in mvc for routing unit test

From Dev

how to unit test a python process

From Dev

Testing for stdout in Python Unit Test

From Dev

How to mock this unit test in Python?

From Dev

Is it possible to force set an internal variable for Unit Test purpose?

From Dev

Error in MockMvc test case for controller