-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Logging error when plugin is using old-style hook wrappers when pytest is not #11714
Comments
Thanks for trying pytest main and pinning down the commit. I am able to reproduce, I'll take a look in the next few days. |
Just from a quick look so I won't forget: it seems like the logging teardown is deferred until GC instead of being executed immediately; this causes it to happen after the The issue therefore must lie in pluggy not |
Looked into it now. The problem is pytest-dev/pluggy#244, which was the focus of the latest pluggy releases. Unfortunately there was no way to fix it for old-style hookwrappers transparently (due to backward compat). So you must either change to new-style wrappers or use the new If you're willing to require diff --git a/pytest_mpl/plugin.py b/pytest_mpl/plugin.py
index 625bf99..040652c 100644
--- a/pytest_mpl/plugin.py
+++ b/pytest_mpl/plugin.py
@@ -803,7 +803,8 @@ class ImageComparison:
# Run test and get figure object
wrap_figure_interceptor(self, item)
- yield
+ result = yield
+ try:
if test_name not in self.return_value:
# Test function did not complete successfully
summary['status'] = 'failed'
@@ -864,6 +865,8 @@ class ImageComparison:
if summary['status'] == 'skipped':
pytest.skip(summary['status_msg'])
+ except BaseException as e:
+ result.force_exception(e)
def generate_summary_json(self):
json_file = self.results_dir / 'results.json'
or switch to new-style wrappers (just replace If you can't require new pluggy, I guess you can "polyfill" if hasattr(result, "force_exception"): # pluggy>=1.2.0
result.force_exception(e)
else:
result._result = None
result._excinfo = (type(e), e, e.__traceback__) Technical details if you're interested: The problem is: with old-style hookwrappers, you must not raise from the teardown. If the teardown raises, it causes the following teardowns to be skipped, and they are then collected by GC at some later point. This is what happens in pytest-mpl:
|
Thanks @bluetech, that's really helpful and it's interesting to learn more about the internals! We've now updated pytest-mpl to use either the |
Since #11123 switched from the old-style hook wrappers to the new-style hook wrappers, I'm getting an error in the
pytest-mpl
plugin tests when testing with pytest'smain
branch installed. If I upgradepytest-mpl
to use the new-style hook wrappers in itspytest_runtest_call
, the error goes away. I thought I would log the issue here in case it will cause wider issues when pytest 8 is released.I'm seeing this: https://github.com/matplotlib/pytest-mpl/actions/runs/7233619388/job/19709093922#step:10:4021
I can't really find a minimal example as the failure appears in different tests between test runs and it usually only occurs when I run the full test suite. I thought it might be related to pytester but then I saw it occurring in some non-pytester tests.
To be clear, if I checkout b41acae in the tests they fail, but if I checkout the previous commit they pass. I'm not sure where to look to isolate the issue, but maybe someone who knows the pytest codebase better would.
I think I'll upgrade
pytest-mpl
to use the new-style hook wrappers. Would you recommend using the new style ifpytest>=8
or ifpluggy>=1.2
? Thanks 🙂The text was updated successfully, but these errors were encountered: