Example #1
0
def test_can_trap_errors_but_fail_due_to_type():
    try:
        with expect.not_error_to_happen(RuntimeError):
            raise ValueError("something is wrong")
    except AssertionError:
        err = sys.exc_info()[1]
        expect(str(err)).to_include(
            'ValueError" happened during execution of with block.')
        return

    expect.not_to_be_here()
Example #2
0
def test_can_NOT_trap_errors():
    try:
        with expect.not_error_to_happen(RuntimeError):
            raise RuntimeError("something is wrong")
    except AssertionError:
        err = sys.exc_info()[1]
        expect(str(err)).to_include(
            'not to happen but it happened during execution of with block.')
        return

    expect.not_to_be_here()
Example #3
0
def test_can_trap_errors_but_fail_due_to_message():
    try:
        with expect.not_error_to_happen(RuntimeError, message="qweqwe"):
            raise RuntimeError("something is wrong")
    except AssertionError:
        err = sys.exc_info()[1]
        expect(str(err)).to_include(
            'to have a message of "qweqwe", but the actual error was "something is wrong".'
        )
        return

    expect.not_to_be_here()
Example #4
0
def test_can_trap_errors_but_fail_due_to_message():
    try:
        with expect.not_error_to_happen(RuntimeError, message="qweqwe"):
            raise RuntimeError("something is wrong")
    except AssertionError:
        err = sys.exc_info()[1]
        expect(str(err)).to_include(
            'to have a message of "qweqwe", but the actual error was "something is wrong".'
        )
        return

    expect.not_to_be_here()
Example #5
0
def test_can_trap_errors_but_fail_due_to_type():
    try:
        with expect.not_error_to_happen(RuntimeError):
            raise ValueError("something is wrong")
    except AssertionError:
        err = sys.exc_info()[1]
        expect(str(err)).to_include(
            'ValueError" happened during execution of with block.'
        )
        return

    expect.not_to_be_here()
Example #6
0
def test_can_NOT_trap_errors():
    try:
        with expect.not_error_to_happen(RuntimeError):
            raise RuntimeError("something is wrong")
    except AssertionError:
        err = sys.exc_info()[1]
        expect(str(err)).to_include(
            'not to happen but it happened during execution of with block.'
        )
        return

    expect.not_to_be_here()