-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
WIP for 5510 [skip ci] #5511
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
Closed
Closed
WIP for 5510 [skip ci] #5511
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1335,23 +1335,25 @@ def test(): | |
|
|
||
|
|
||
| class TestAssertionPass: | ||
| @pytest.fixture | ||
| def ini(self, testdir): | ||
| testdir.makeini( | ||
| """ | ||
| [pytest] | ||
| enable_assertion_pass_hook = True | ||
| """ | ||
| ) | ||
|
|
||
| def test_option_default(self, testdir): | ||
| config = testdir.parseconfig() | ||
| assert config.getini("enable_assertion_pass_hook") is False | ||
|
|
||
| def test_hook_call(self, testdir): | ||
| def test_hook_call_expr(self, testdir, ini): | ||
| testdir.makeconftest( | ||
| """ | ||
| def pytest_assertion_pass(item, lineno, orig, expl): | ||
| raise Exception("Assertion Passed: {} {} at line {}".format(orig, expl, lineno)) | ||
| """ | ||
| ) | ||
|
|
||
| testdir.makeini( | ||
| pass | ||
| """ | ||
| [pytest] | ||
| enable_assertion_pass_hook = True | ||
| """ | ||
| ) | ||
|
|
||
| testdir.makepyfile( | ||
|
|
@@ -1369,12 +1371,15 @@ def test_fails(): | |
| assert False, "assert with message" | ||
| """ | ||
| ) | ||
| result = testdir.runpytest() | ||
| result.stdout.fnmatch_lines( | ||
| "*Assertion Passed: a + b == c + d (1 + 2) == (3 + 0) at line 7*" | ||
| rec = testdir.inline_run() | ||
| calls = rec.getcalls("pytest_assertion_pass") | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @asottile this might be useful too, using |
||
| assert len(calls) == 1 | ||
| calls[0].assert_params( | ||
| orig="(a + b == c + d)", expl="(1 + 2) == (3 + 0)", lineno=7 | ||
| ) | ||
| assert calls[0].item.nodeid == "test_hook_call_expr.py::test_simple" | ||
|
|
||
| def test_hook_not_called_without_hookimpl(self, testdir, monkeypatch): | ||
| def test_hook_not_called_without_hookimpl(self, testdir, monkeypatch, ini): | ||
| """Assertion pass should not be called (and hence formatting should | ||
| not occur) if there is no hook declared for pytest_assertion_pass""" | ||
|
|
||
|
|
@@ -1385,13 +1390,6 @@ def raise_on_assertionpass(*_, **__): | |
| _pytest.assertion.rewrite, "_call_assertion_pass", raise_on_assertionpass | ||
| ) | ||
|
|
||
| testdir.makeini( | ||
| """ | ||
| [pytest] | ||
| enable_assertion_pass_hook = True | ||
| """ | ||
| ) | ||
|
|
||
| testdir.makepyfile( | ||
| """ | ||
| def test_simple(): | ||
|
|
@@ -1424,13 +1422,6 @@ def pytest_assertion_pass(item, lineno, orig, expl): | |
| """ | ||
| ) | ||
|
|
||
| testdir.makeini( | ||
| """ | ||
| [pytest] | ||
| enable_assertion_pass_hook = False | ||
| """ | ||
| ) | ||
|
|
||
| testdir.makepyfile( | ||
| """ | ||
| def test_simple(): | ||
|
|
||
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.
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.
@asottile this might be useful