Last active
November 7, 2023 17:26
-
-
Save s0undt3ch/92d065815f4ce526345f72d40a40074d to your computer and use it in GitHub Desktop.
Explain Pytest Assertion With Expected Data Last as Opposed to First
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
===================================================================================================== FAILURES ====================================================================================================== | |
________________________________________________________________________________________________ test_expected_first ________________________________________________________________________________________________ | |
def test_expected_first(): | |
expected = { | |
"one": 1, | |
"two": 2, | |
} | |
ret = { | |
"one": 1, | |
"two": 2, | |
"three": 3, | |
} | |
> assert expected == ret | |
E AssertionError: assert {'one': 1, 'two': 2} == {'one': 1, 'two': 2, 'three': 3} | |
E Common items: | |
E {'one': 1, 'two': 2} | |
E Right contains 1 more item: | |
E {'three': 3} | |
E Full diff: | |
E - {'one': 1, 'three': 3, 'two': 2} | |
E ? ------------ | |
E + {'one': 1, 'two': 2} | |
expected = {'one': 1, 'two': 2} | |
ret = {'one': 1, 'three': 3, 'two': 2} | |
tests/pytests/unit/test_diff.py:12: AssertionError | |
________________________________________________________________________________________________ test_expected_last _________________________________________________________________________________________________ | |
def test_expected_last(): | |
expected = { | |
"one": 1, | |
"two": 2, | |
} | |
ret = { | |
"one": 1, | |
"two": 2, | |
"three": 3, | |
} | |
> assert ret == expected | |
E AssertionError: assert {'one': 1, 'two': 2, 'three': 3} == {'one': 1, 'two': 2} | |
E Common items: | |
E {'one': 1, 'two': 2} | |
E Left contains 1 more item: | |
E {'three': 3} | |
E Full diff: | |
E - {'one': 1, 'two': 2} | |
E + {'one': 1, 'three': 3, 'two': 2} | |
E ? ++++++++++++ | |
expected = {'one': 1, 'two': 2} | |
ret = {'one': 1, 'three': 3, 'two': 2} | |
tests/pytests/unit/test_diff.py:24: AssertionError | |
---------------------------------------- generated xml file: /home/vampas/projects/SaltStack/salt/hotfix/merge-forward/artifacts/xml-unittests-output/test-results-grp1.xml ----------------------------------------- | |
============================================================================================== short test summary info ============================================================================================== | |
FAILED tests/pytests/unit/test_diff.py::test_expected_first - AssertionError: assert {'one': 1, 'two': 2} == {'one': 1, 'two': 2, 'three': 3} | |
FAILED tests/pytests/unit/test_diff.py::test_expected_last - AssertionError: assert {'one': 1, 'two': 2, 'three': 3} == {'one': 1, 'two': 2} | |
================================================================================================= 2 failed in 1.03s ================================================================================================= |
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
def test_expected_first(): | |
expected = { | |
"one": 1, | |
"two": 2, | |
} | |
ret = { | |
"one": 1, | |
"two": 2, | |
"three": 3, | |
} | |
assert expected == ret | |
def test_expected_last(): | |
expected = { | |
"one": 1, | |
"two": 2, | |
} | |
ret = { | |
"one": 1, | |
"two": 2, | |
"three": 3, | |
} | |
assert ret == expected |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment