Open tonybaloney opened 1 month ago
Something like this?
@pytest.hookimpl
def pytest_runtest_call(item: pytest.Item):
# Try item.runtest()
runtime_err_val = "The global interpreter lock (GIL) has been enabled to load module"
logger.debug("Running test %s", item.name)
executor = ThreadPoolExecutor(max_workers=20)
results = list(executor.submit(get_one_result, [item] * 200))
exceptions = [isinstance(r, Exception) for r in results]
filtered_exceptions = []
for e in exceptions:
if hasattr(e, message) and runtime_err_val in e.message:
logger.error(e)
return results[0]
else:
filtered_exceptions.append(e)
if all(exceptions):
raise results[0]
if all(not e for e in exceptions):
return results[0]
raise Exception("Result discrepancy") from next(r for r in results if isinstance(r, Exception))
This catches and logs the correct warning now, but haven't managed to figure out how to convert them to errors: https://github.com/tonybaloney/pytest-freethreaded/blob/nogil_modules
When you import a C extension that does not support no-GIL, it will raise a warning in CPython, see https://py-free-threading.github.io/porting/
We should capture these warnings and log them in the tests.
Example:
If you made this as a test:
Should fail the test because it raised the
RuntimeWarning
, see https://docs.pytest.org/en/7.1.x/how-to/capture-warnings.html#warns