Skip to content

Instantly share code, notes, and snippets.

@hltbra
Created December 16, 2013 16:33
Show Gist options
  • Select an option

  • Save hltbra/7989959 to your computer and use it in GitHub Desktop.

Select an option

Save hltbra/7989959 to your computer and use it in GitHub Desktop.
# WRONG
def test_open_and_delete_file():
f = open(FILEPATH)
content = f.read()
assert content == "hello world"
content.close()
# RIGHT
def test_open_and_delete_file():
f = open(FILEPATH)
try:
content = f.read()
assert content == "hello world"
finally:
content.close()
# WRONG
def test_create_user():
u = create_user(username="test")
assert count_users() == 1
flush_db()
# RIGHT
def test_create_user():
try:
u = create_user(username="test")
assert count_users() == 1
finally:
flush_db()
# WRONG
def test_create_multiple_users():
u = create_users(usernames=["test", "test2"])
assert count_users() == 2
flush_db()
# RIGHT
def test_create_multiple_users():
try:
u = create_users(usernames=["test", "test2"])
assert count_users() == 2
finally:
flush_db()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment