votes up 2

Expected exception

Package:
Exception Class:
Exception

Raise code

def test_set_environ_raises_exception():
    """Tests set_environ will raise exceptions in context when the
    value parameter is None."""
    with pytest.raises(Exception) as exception:
        with set_environ('test1', None):
            raise Exception('Expected exception')

    assert 'Expected exception' in str(exception.value)
🙏 Scream for help to Ukraine
Today, 14th August 2022, Russia continues bombing and firing Ukraine. Don't trust Russia, they are bombing us and brazenly lying in same time they are not doing this 😠, civilians and children are dying too! We are screaming and asking exactly you to help us, we want to survive, our families, children, older ones.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.

Ways to fix

votes up 1 votes down

This exception is dropped by requests UnitTests.

with pytest.raises(Exception)

Just makes sure that the inner code will raise an exception.

The code:

raise Exception('Expected exception')

Makes raise itself.

Then

assert 'Expected exception' in str(exception.value)

Checks that exception string is right

Jun 03, 2021 brucehardywald answer

Add a possible fix

Please authorize to post fix