Skip to content

remove pytest_exception_interact hook#197

Merged
flub merged 1 commit into
pytest-dev:mainfrom
timoffex:main
Jun 30, 2026
Merged

remove pytest_exception_interact hook#197
flub merged 1 commit into
pytest-dev:mainfrom
timoffex:main

Conversation

@timoffex

Copy link
Copy Markdown
Contributor

Removes the hook so that fixture teardowns can time out after a failed test. See issue #196 for details!

The pytest_enter_pdb hook handles debugger interactions, so I believe the original purpose of this hook is covered. I can't think of any other reason someone might find this behavior useful.

@timoffex timoffex marked this pull request as ready for review June 29, 2026 19:07

@flub flub left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, have you tested the --pdb behaviour?

Comment thread test_pytest_timeout.py Outdated

def test_foo(self, fix):
pass
{"assert False" if fail else "pass"}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can assert {fail} or something close to it work? seems slightly simpler

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea, updated!

@timoffex

Copy link
Copy Markdown
Contributor Author

Interesting, have you tested the --pdb behaviour?

Yes, tried that out as well. I used this script:

import time

import pytest


@pytest.fixture
def bad_fixture():
    yield
    time.sleep(5)


def test_timeout(bad_fixture):
    assert False

And ran it with pytest --pdb --timeout 1. It enters the debugger on assert False and cancels the timeout (it doesn't trigger if you sit in the debugger for a few seconds, and it doesn't trigger in bad_fixture afterward if you use the continue command).

@timoffex timoffex requested a review from flub June 30, 2026 17:05
@flub

flub commented Jun 30, 2026

Copy link
Copy Markdown
Member

I assume this breaks compatibility with some older versions of pytest. But we already require pytest >= 7.0 which was from 2022 it seems. Which is way older than 2014 when the newer hook was added.

@flub flub merged commit 3912a19 into pytest-dev:main Jun 30, 2026
10 checks passed
@timoffex

Copy link
Copy Markdown
Contributor Author

Looks like it's pytest>=8.0.0 for the upcoming release. I tested with pytest==8.0.0 as well just to make sure; everything seems fine!

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