• 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 를 뿜는다.




+ Recent posts