Skip to content
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

Remove astor and reproduce the original assertion expression #5512

Merged
merged 1 commit into from Jun 28, 2019
Merged

Remove astor and reproduce the original assertion expression #5512

merged 1 commit into from Jun 28, 2019

Conversation

asottile
Copy link
Member

Resolves #5510

This is a little different approach than using astor in that it reproduces the original assertion source expression directly

I could make this even simpler by including the whole line of the original assertion (then the indentation would be preserved as well???) what do you think of that?

@codecov
Copy link

codecov bot commented Jun 28, 2019

Codecov Report

Merging #5512 into master will decrease coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5512      +/-   ##
==========================================
- Coverage   96.09%   96.06%   -0.03%     
==========================================
  Files         117      117              
  Lines       25647    25697      +50     
  Branches     2483     2494      +11     
==========================================
+ Hits        24646    24687      +41     
- Misses        696      702       +6     
- Partials      305      308       +3
Impacted Files Coverage Δ
src/_pytest/assertion/rewrite.py 96.08% <100%> (+0.32%) ⬆️
testing/test_assertrewrite.py 84.68% <100%> (+0.15%) ⬆️
src/_pytest/assertion/util.py 92.36% <0%> (-2.68%) ⬇️
src/_pytest/doctest.py 95.16% <0%> (-0.75%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3c9b46f...7ee2444. Read the comment docs.

@@ -285,7 +287,7 @@ def _rewrite_test(fn, config):
with open(fn, "rb") as f:
source = f.read()
tree = ast.parse(source, filename=fn)
rewrite_asserts(tree, fn, config)
rewrite_asserts(tree, source, fn, config)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that this is a blocker, but this will end up breaking https://pypi.org/project/pytest-ast-back-to-python.

cc @tomviner

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, I can restore the api and just re-read the source in the visitor using fn

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to update here, pytest-ast-back-to-python has now been fixed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome Tom, thanks for the heads up!

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for working on this @asottile!

I feel a little off in that we might be reinventing the wheel, but if astor does not provide the functionality we need correctly, we might need to implement our own, thanks for that. 👍

src/_pytest/assertion/rewrite.py Show resolved Hide resolved
testing/test_assertrewrite.py Show resolved Hide resolved
@@ -1371,10 +1371,21 @@ def test_fails():
)
result = testdir.runpytest()
result.stdout.fnmatch_lines(
"*Assertion Passed: a + b == c + d (1 + 2) == (3 + 0) at line 7*"
"*Assertion Passed: a+b == c+d (1 + 2) == (3 + 0) at line 7*"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you see the approach I took in #5511 of using inline_run and checking the parameters received by the hook directly? Feels more elegant that way as we can check the parameters directly instead of relying on parsed output.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did yeah, didn't quite feel like expanding the api scope of pytester further but I can take another look at that again 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a two-liner helper function to ParsedCall, that's all. I think it is an improvement.

Anyway just a suggestion really. 👍

Copy link
Member

@nicoddemus nicoddemus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks!

@nicoddemus nicoddemus merged commit 73d918d into pytest-dev:master Jun 28, 2019
@asottile asottile deleted the remove_astor branch June 28, 2019 21:36
@asottile
Copy link
Member Author

alrighty, let me replay the release branch :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pytest_assertion_pass strange results
3 participants