Skip to content

Update assertion to check for subclass of RuntimeError#14665

Closed
FadyMorris wants to merge 1 commit into
pytest-dev:mainfrom
FadyMorris:patch-2
Closed

Update assertion to check for subclass of RuntimeError#14665
FadyMorris wants to merge 1 commit into
pytest-dev:mainfrom
FadyMorris:patch-2

Conversation

@FadyMorris

Copy link
Copy Markdown

This pull request makes a minor update to the documentation to clarify how to check for exception types in pytest. The assertion now uses issubclass instead of is to correctly verify that the raised exception is a subclass of the expected type.

  • Documentation update:
    • Changed the assertion in the pytest example from excinfo.type is RuntimeError to issubclass(excinfo.type, RuntimeError) in doc/en/how-to/assert.rst to accurately check for subclass relationships when verifying raised exceptions.Change assertion to check for subclass of RuntimeError.

Change assertion to check for subclass of RuntimeError.
@The-Compiler

Copy link
Copy Markdown
Member

From right above what you changed:

Note that pytest.raises will match the exception type or any subclasses (like the standard except statement). If you want to check if a block of code is raising an exact exception type, you need to check that explicitly: [... ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants