Skip to content

Instantly share code, notes, and snippets.

@medwards
Created October 24, 2014 09:45
Show Gist options
  • Save medwards/2fc2ae1c42f8ee7becbf to your computer and use it in GitHub Desktop.
Save medwards/2fc2ae1c42f8ee7becbf to your computer and use it in GitHub Desktop.
Expected GOES FIRST
from nose.tools import assert_equals # pip install nosetests
assert_equals("first", "second")
# Nothing fancy here, just default string comparison
# AssertionError: 'first' != 'second'
# Lets compare a dictionary
assert_equals({'a': 'foo'}, {'a': 'bar'})
# This produces a cool little diff
# AssertionError: {'a': 'foo'} != {'a': 'bar'}
# - {'a': 'foo'}
# ? ^^^
#
# + {'a': 'bar'}
# ? ^^^
# When our test fails we want to know how the test result deviates from the expected result.
# Convention in diff output (as above) puts the 'baseline' value first
# So, kids, assert_equals(expected, result) for great justice
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment