- 공식사이트 : http://pytest.org/latest/
- Installation Document Page : http://pytest.org/latest/getting-started.html
- Example Page : http://pytest.org/latest/example/index.html
Install
juce@juce-ubuntu:~$ sudo -H pip install -U pytest
Downloading/unpacking pytest
Downloading pytest-2.8.5-py2.py3-none-any.whl (151kB): 151kB downloaded
Downloading/unpacking py>=1.4.29 (from pytest)
Downloading py-1.4.31-py2.py3-none-any.whl (81kB): 81kB downloaded
Installing collected packages: pytest, py
Successfully installed pytest py
Cleaning up...
juce@juce-ubuntu:~$
Example
##
# -*- coding: utf-8 -*-
import pytest
# example function to test
def func_test(x):
return x + 1
def test_answer():
assert func_test(3) == 5
if __name__ == '__main__':
test_answer()
- testing
juce@juce-ubuntu:~/study/python/basic$ py.test -q python_pytest.py
F
======================================== FAILURES =========================================
_______________________________________ test_answer _______________________________________
def test_answer():
> assert func_test(3) == 5
E assert 4 == 5
E + where 4 = func_test(3)
python_pytest.py:12: AssertionError
1 failed in 0.00 seconds
juce@juce-ubuntu:~/study/python/basic$
- py.test -q ['테스트할 파일명']
- 위의 예제에서는 func_test(3) 의 결과가 4 이고,
- assert func_test(3) == 5 라고 선언해 논 부분에서 match 가 되지 않아 pass 에 실패했으므로
- Error 를 뿜는다.
- 자세한 사용 예제는 다음 링크를 참조한다.
'Python > Study' 카테고리의 다른 글
Python | Study | Weppy installation | Weppy 설치하기 (0) | 2016.01.22 |
---|---|
Python | Study | ipaddress 설치 (0) | 2016.01.22 |
Python | Study | Data Type Conversion (0) | 2016.01.15 |
Python | Study | lambda function Basic (0) | 2016.01.14 |
Python | Examples | OpenPyXL 사용하기 | python - excel 파일 다루기 (0) | 2016.01.13 |