-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
add support for printing the diff of AST trees when running tests #3902
Conversation
This is a good, idea, thanks! The full AST is indeed insanely long. A few thoughts:
|
I just realized, this would be much easier to use if added as a CLI option in
yeah, let's rename them at the same time. |
…t variable to a pytest option, add test and update old test to work with patching, remove py37 from tox default envlist
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.
Thanks! Left some comments mostly on wording.
tests/util.py
Outdated
ast_print = not os.environ.get("SKIP_AST_PRINT") | ||
ast_print_diff = not os.environ.get("SKIP_AST_PRINT_DIFF") | ||
if actual != expected and (ast_print or ast_print_diff): | ||
# need to import inside the function for the monkeypatching tests to work |
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.
Another approach which should work and I think is cleaner is to do from . import conftest
in the global scope, and then use the qualified names like conftest.PRINT_FULL_TREE
here.
Co-authored-by: Jelle Zijlstra <[email protected]>
for more information, see https://pre-commit.ci
The CI fail seem unrelated to this PR |
Description
As I've been working more on Black, I found the full printing of AST trees to be cumbersome and insanely long, but it regardless often containing necessary info, so I ended up modifying the value of that variable a lot and/or temporarily splitting tests into shorter files. But realized that diff-printing would solve that issue, and while not as simple as I'd initially hoped it wasn't too tricky to work out and is turning out very useful.
Checklist - did you ...
CHANGES.md
if necessary?I don't think changes to test QoL warrants entries in
CHANGES.md
Given the precedence of
test_assertFormatEqual
I should probably write one."SKIP_AST_PRINT"
isn't documented anywhere, but it and this should probably be inCONTRIBUTING.md
and/or the contributing documentation on RTD - it took me a while to find myself.