Update conftest.py for pluggy 1.1 (#4448)

pluggy >=1.1 makes really annoying warnings if the original wrapper hooks raise errors
telling us to use the new style wrapper. This follows their advice to get rid of the warnings.
This commit is contained in:
Hood Chatham 2024-01-31 11:18:57 -08:00 committed by GitHub
parent ca1aac29d6
commit 2eb834b32d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 15 additions and 13 deletions

View File

@ -2,6 +2,7 @@
Various common utilities for testing.
"""
import contextlib
import os
import pathlib
import re
@ -191,7 +192,7 @@ def pytest_terminal_summary(terminalreporter):
cache.set("cache/lasttestresult", test_result)
@pytest.hookimpl(hookwrapper=True)
@pytest.hookimpl(wrapper=True)
def pytest_runtest_call(item):
"""We want to run extra verification at the start and end of each test to
check that we haven't leaked memory. According to pytest issue #5044, it's
@ -211,8 +212,8 @@ def pytest_runtest_call(item):
break
if not browser or not browser.pyodide_loaded:
yield
return
result = yield
return result
trace_pyproxies = pytest.mark.skip_pyproxy_check.mark not in item.own_markers
trace_hiwire_refs = (
@ -232,18 +233,18 @@ def extra_checks_test_wrapper(browser, trace_hiwire_refs, trace_pyproxies):
if trace_pyproxies:
browser.enable_pyproxy_tracing()
init_num_proxies = browser.get_num_proxies()
a = yield
err = False
try:
# If these guys cause a crash because the test really screwed things up,
# we override the error message with the better message returned by
# a.result() in the finally block.
browser.disable_pyproxy_tracing()
browser.restore_state()
result = yield
except Exception:
err = True
raise
finally:
# if there was an error in the body of the test, flush it out by calling
# get_result (we don't want to override the error message by raising a
# different error here.)
a.get_result()
# Suppress any errors if an error was raised so we keep the orignal error
with contextlib.suppress(Exception) if err else contextlib.nullcontext():
browser.disable_pyproxy_tracing()
browser.restore_state()
if browser.force_test_fail:
raise Exception("Test failure explicitly requested but no error was raised.")
if trace_pyproxies and trace_hiwire_refs:
@ -253,6 +254,7 @@ def extra_checks_test_wrapper(browser, trace_hiwire_refs, trace_pyproxies):
if trace_hiwire_refs:
delta_keys = browser.get_num_hiwire_keys() - init_num_keys
assert delta_keys <= 0
return result
def package_is_built(package_name):