Conversation
This changes testlib to propagate error context correctly from the tests inside workerd back out to the host pytest session. Previously, any error traceback would always show the host code that looked up the test results which is test support code and not related to the actual cause of the problem. Now it shows correct tracebacks. The techniques here are based on similar techniques in pytest-pyodide. Using tblib + pickle we serialize exceptions. For robustness we use a custom pickler that pickles most things into strings, other than builtin types and types from tblib which we need to handle correctly. On the unpickling side, we synthesize dummy exception classes on the fly for any exceptions that are missing. This is a simpler way to deal with the problems we've had in pytest-pyodide with tracebacks being messed up for exception classes that are only defined in the Pyodide session. I used a fork of tblib called pyodide-tblib for the traceback serializing. It includes ionelmc/python-tblib#91 which fixes column positioning, a fix that makes multiline positions work correctly, and a fix that gets the first line of functions correct. This makes the context exactly match what pytest would show natively.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This changes testlib to propagate error context correctly from the tests inside workerd back out to the host pytest session. Previously, any error traceback would always show the host code that looked up the test results which is test support code and not related to the actual cause of the problem. Now it shows correct tracebacks. The techniques here are based on similar techniques in pytest-pyodide.
Using tblib + pickle we serialize exceptions. For robustness we use a custom pickler that pickles most things into strings, other than builtin types and types from tblib which we need to handle correctly.
On the unpickling side, we synthesize dummy exception classes on the fly for any exceptions that are missing. This is a simpler way to deal with the problems we've had in pytest-pyodide with tracebacks being messed up for exception classes that are only defined in the Pyodide session.
I used a fork of tblib called pyodide-tblib for the traceback serializing. It includes ionelmc/python-tblib#91 which fixes column positioning, a fix that makes multiline positions work correctly, and a fix that gets the first line of functions correct. This makes the context exactly match what pytest would show natively.
Before
After