잠토의 잠망경

[vscode] unit test 설정 - with python 본문

만화경

[vscode] unit test 설정 - with python

잠수함토끼 2021. 1. 17. 10:13

VSCode로 python을 작성하려한다.

가장 기본이 되는 unittest를 하기 위한 환경 설정이 필요하여 기록으로 남긴다.

폴더 구성

index 파일이름
1 settings.json
2 sample009_01.py
3 sample009_01_test.py

사전 준비

{
    "python.pythonPath": "C:\\Users\\xxxxx\\AppData\\Local\\Programs\\Python\\Python36\\python.exe",
    "python.testing.unittestEnabled": false,
    "python.testing.nosetestsEnabled": false,
    "python.testing.pytestEnabled": true
}

unit code sample

Target File()

# sample009_01.py
def sum(a:int, b:int):

    return a+b

Test File(기본 형태)

# sample009_01_test.py
from sample009_01 import sum

import unittest

class Test_Sample01(unittest.TestCase):

    def test_sum(self):

        self.assertTrue(21 == sum(10, 11))

if __name__ == '__main__':
    unittest.main()

사용된 사례

※ 임의로 error를 만듬

참고

https://github.com/microsoft/vscode-python/issues/11513

Comments