Skip to content

Instantly share code, notes, and snippets.

@s0undt3ch
Last active November 7, 2023 17:26
Show Gist options
  • Save s0undt3ch/92d065815f4ce526345f72d40a40074d to your computer and use it in GitHub Desktop.
Save s0undt3ch/92d065815f4ce526345f72d40a40074d to your computer and use it in GitHub Desktop.
Explain Pytest Assertion With Expected Data Last as Opposed to First
===================================================================================================== 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 =================================================================================================
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