-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Detailed assert failure introspection for attrs and dataclasses objects #3776
Merged
nicoddemus
merged 14 commits into
pytest-dev:features
from
alysivji:attrs-n-dataclasses
Nov 22, 2018
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9769bc0
moving plugin inside pytest first pass
alysivji d42f1e8
Add tests for attrs and dataclasses
alysivji a0ba881
Add change to log; name to AUTHORS
alysivji 1184db8
cleaning up
alysivji 87b019d
fix gitignore
alysivji 1847cc7
adding docs and cleaning up
alysivji a3e388a
Improve changelog
alysivji 025d160
Update tests to pass in py27
alysivji e1e81e3
code review 1/n -- change hasattr to getattr
alysivji a663f60
cr 2/n -- refactor compare eq class
alysivji 4e99c80
have tests pass in python37; move to separate file
alysivji 2bffd68
Move dataclass tests for 3.7 to separate file
alysivji b83e978
improve failure output
alysivji d52ea4b
Use python 3 in 'doctesting' environment
nicoddemus 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 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 |
---|---|---|
|
@@ -44,3 +44,4 @@ coverage.xml | |
.pydevproject | ||
.project | ||
.settings | ||
.vscode |
This file contains 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 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
Richer equality comparison introspection on ``AssertionError`` for objects created using `attrs <http://www.attrs.org/en/stable/>`_ or `dataclasses <https://docs.python.org/3/library/dataclasses.html>`_ (Python 3.7+, `backported to 3.6 <https://pypi.org/project/dataclasses>`_). |
This file contains 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 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 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
14 changes: 14 additions & 0 deletions
14
testing/example_scripts/dataclasses/test_compare_dataclasses.py
This file contains 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from dataclasses import dataclass | ||
from dataclasses import field | ||
|
||
|
||
def test_dataclasses(): | ||
@dataclass | ||
class SimpleDataObject(object): | ||
field_a: int = field() | ||
field_b: int = field() | ||
|
||
left = SimpleDataObject(1, "b") | ||
right = SimpleDataObject(1, "c") | ||
|
||
assert left == right |
14 changes: 14 additions & 0 deletions
14
testing/example_scripts/dataclasses/test_compare_dataclasses_field_comparison_off.py
This file contains 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from dataclasses import dataclass | ||
from dataclasses import field | ||
|
||
|
||
def test_dataclasses_with_attribute_comparison_off(): | ||
@dataclass | ||
class SimpleDataObject(object): | ||
field_a: int = field() | ||
field_b: int = field(compare=False) | ||
|
||
left = SimpleDataObject(1, "b") | ||
right = SimpleDataObject(1, "c") | ||
|
||
assert left == right |
14 changes: 14 additions & 0 deletions
14
testing/example_scripts/dataclasses/test_compare_dataclasses_verbose.py
This file contains 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from dataclasses import dataclass | ||
from dataclasses import field | ||
|
||
|
||
def test_dataclasses_verbose(): | ||
@dataclass | ||
class SimpleDataObject(object): | ||
field_a: int = field() | ||
field_b: int = field() | ||
|
||
left = SimpleDataObject(1, "b") | ||
right = SimpleDataObject(1, "c") | ||
|
||
assert left == right |
19 changes: 19 additions & 0 deletions
19
testing/example_scripts/dataclasses/test_compare_two_different_dataclasses.py
This file contains 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from dataclasses import dataclass | ||
from dataclasses import field | ||
|
||
|
||
def test_comparing_two_different_data_classes(): | ||
@dataclass | ||
class SimpleDataObjectOne(object): | ||
field_a: int = field() | ||
field_b: int = field() | ||
|
||
@dataclass | ||
class SimpleDataObjectTwo(object): | ||
field_a: int = field() | ||
field_b: int = field() | ||
|
||
left = SimpleDataObjectOne(1, "b") | ||
right = SimpleDataObjectTwo(1, "c") | ||
|
||
assert left != right |
This file contains 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 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
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.
i disagree with the chosen display style but cant provide any meaningful alternative yet - i would like to see some kind of diff style display using multiple lines