Last active
November 7, 2020 19:24
-
-
Save gidgid/2a373857cd43f0c9bafdba4ca1489e92 to your computer and use it in GitHub Desktop.
Same keys and values cause dicts to be equal but data classes are still different
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
from dataclasses import dataclass | |
def test_given_dicts_with_the_same_keys_values_then_they_are_equal(): | |
user = {"name": "John", "lastname": "Doe", "age": 42} | |
employee = {"name": "John", "lastname": "Doe", "age": 42} | |
assert user == employee, "Ideally, these would be different" | |
@dataclass | |
class User: | |
name: str | |
lastname: str | |
age: int | |
@dataclass | |
class Employee: | |
name: str | |
lastname: str | |
age: int | |
def test_given_classes_with_same_keys_values_then_they_are_different(): | |
user = User(name="John", lastname="Doe", age=42) | |
employee = Employee(name="John", lastname="Doe", age=42) | |
assert user != employee, "This is what we really want" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment