Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

expected exceptions #41

Copy link
Copy link
@sstirlin

Description

@sstirlin
Issue body actions

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")
Reactions are currently unavailable

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.