-
Notifications
You must be signed in to change notification settings - Fork 9
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
Improve test collection and output #160
Conversation
@despadam It's a small modification of your implementation. Comments/suggestions are welcome! |
Thanks @edoardob90 🙏👍 I will review it tomorrow |
Thanks. Have a look and try it out, there might be some edge cases I did not handle. Also: we're collecting the full traceback with your We can then change the draft status and do some cleanup/rewriting some bits in a better way. |
It's a great starting point and we did good progress today. We can merge it soon and later change as needed. it is great to have structured information on test failure and not having to extract it from the very verbose stdout |
tutorial/tests/testsuite_helpers.py
Outdated
success=False, | ||
stdout=None, | ||
stderr=None, | ||
exception=traceback.format_exception_only(call.excinfo.value), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer that the formatting happens at the time of construction of the test output.
We could store the excinfo here and call the method later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent work @edoardob90. I have a few ideas, with your agreement I will just create a new commit with those.
tutorial/tests/testsuite_helpers.py
Outdated
stdout: str | None | ||
stderr: str | None | ||
exception: List[str] | None | ||
traceback: List[str] | None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add a status
variable instead of success
. This could have the following states:
- Passed
- Failed
- Syntax error
In this way we can also report syntax errors or any other error that happens during the test collection phase but before the test is run.
Following changes should be added:
|
A lot of this was achieved today in a monster refactor with @edoardob90 🔥. Missing:
|
Added the following:
|
Fixed pre-commit.
…mpa-scientific-it/python-tutorial into fix/improve-test-collection-and-output
Tidbits from the last commit:
|
Great work today @edoardob90 🔥. Let's merge this soon and get back to the course materials |
In the last commit:
It might not be necessary to capture the outputs/errors from all the tests, but we cannot know in advance if some output is tied to the input of the solution function. For example, in this case, it's redundant: def solution_power2(x: int) -> int:
print("name")
return x * 2 because the same string will be printed every time. While in the following case it's not: def solution_power2(x: int) -> int:
print("x is", x)
return x * 2 I don't see another way of dealing with this. |
Thanks @edoardob90 , we did good progress today! Now missing:
|
Shall we merge this? |
* Added testing of async functions. * Add 'async' keyword to %%ipytest --------- Co-authored-by: Edoardo Baldi <edoardob90@gmail.com>
There's still one TODO left: catching if an exception is raised in the solution function. Check out #165 . Right now, if that happens, the test outcome is set to |
Changes how the test report is collected and the output message printed to the user.
Beware that the
format_assertion_error
function might not handle all cases. By default, if no special case is found with the assertion, the message is printed as-is, converted to HTML.Lines
124-126
oftestsuite.py
will be irrelevant when the PR on async testing is merged, but I needed them for testing purposes.