Skip to content

Instantly share code, notes, and snippets.

@dahyun31x
Created November 10, 2021 02:27
Show Gist options
  • Save dahyun31x/b553cc88e7798d6916287b6ea2645707 to your computer and use it in GitHub Desktop.
Save dahyun31x/b553cc88e7798d6916287b6ea2645707 to your computer and use it in GitHub Desktop.
pytest로 입출력을 테스트하는 방법
import csv
from io import StringIO
# 입력 스트림을 테스트, 출력 (스트링을 스트림으로 만들 수도 있음)
def test_load_csv():
raw = StringIO('a,b,c\n1,2,3\n4,5,6') # string을 stream으로 변경
actual = load_csv(raw)
expected = [
{'a': '1', 'b': '2', 'c': '3'},
{'a': '4', 'b': '5', 'c': '6'},
]
assert expected == actual
def load_csv(f):
return list(csv.DictReader(f))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment