Skip to content

expected exceptions #41

Description

@sstirlin

The Nim testrunner has a handy "expect" context that ensures that the expected exception is thrown. It works like this:

  test "Making sure that this throws a RangeError":
    expect RangeError:
      var a = myArray[-1]

I'm wondering if something like this can be added to assertpy. Right now the docs say to do this:

    try:
        some_func('bad arg')
        fail('should have raised error')
    except ValueError, ex:
        assert_that(ex.message).contains('some msg')

...But something like this might be nice:

    assert_that(some_func('bad arg')).raises(RuntimeError).with_message("some msg")

Or maybe this:

    assert_that(RuntimeError).is_raised_by(some_func('bad arg'))  # don't care about message
    assert_that(RuntimeError).is_raised_by(some_func('bad arg')).with_message("some msg")

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions