Use TestCase.assertRaises
(or TestCase.failUnlessRaises
) from the unittest module, for example:
import mymod
class MyTestCase(unittest.TestCase):
def test1(self):
self.assertRaises(SomeCoolException, mymod.myfunc)
More Related Contents:
- Why doesn’t Python run my bash code?
- PATH issue with pytest ‘ImportError: No module named YadaYadaYada’
- Is it a good practice to use try-except-else in Python?
- Running unittest with typical test directory structure
- Catch a thread’s exception in the caller thread?
- How to print an exception in Python?
- How to properly assert that an exception gets raised in pytest?
- Run / Debug a Django application’s UnitTests from the mouse right click context menu in PyCharm Community Edition?
- When I catch an exception, how do I get the type, file, and line number?
- How do I run all Python unit tests in a directory?
- Python unittest.TestCase execution order
- changing order of unit tests in Python
- Where do the Python unit tests go? [closed]
- How to test a function with input call?
- How to get exception message in Python properly
- How to assert output with nosetest/unittest in python?
- Python unittest passing arguments
- Python type hinting with exceptions
- How can I create a ramdisk in Python?
- Python: How to ignore an exception and proceed? [duplicate]
- How can I disable logging while running unit tests in Python Django?
- Mock Python’s built in print function
- Is there a difference between “raise exception()” and “raise exception” without parenthesis?
- Mocking Functions Using Python Mock
- Getting the exception value in Python
- Running a specific test case in Django when your app has a tests directory
- Unit testing a python app that uses the requests library
- Python Unit Testing: Automatically Running the Debugger when a test fails
- How can I specify a database for Django Tests to use instead of having it build it every time?
- ‘sys.excepthook’ and threading