-
[Github] GitHub action, Pytest 기반 자동 테스트 세팅기타 2022. 5. 7. 00:33더보기
출처 : https://github.com/serithemage/python_algorithm_exercise
GitHub - serithemage/python_algorithm_exercise
Contribute to serithemage/python_algorithm_exercise development by creating an account on GitHub.
github.com
https://ko.wikipedia.org/wiki/%EC%BD%94%EB%93%9C_%EC%BB%A4%EB%B2%84%EB%A6%AC%EC%A7%80
뭐 때문에? 코드 커버리지 때문에
코드 커버리지(Code Coverage)는 소프트웨어 테스트가 충분한가를 나타내는 지표 중 하나다.
코드가 얼마나 요구와 기대에 충족하는가. 소프트웨어 테스트를 진행했을 때 코드가 얼마나 통과하는가를 의미한다.
그리고 이러한 코드 커버리지를 측정하기 위해 진행하는 테스트를 자동화하는 것은 스스로를 위해서 필수이다.
Git Actions workflow 생성
name: UnitTest on: # 아래의 상황에서 action을 시작한다. push: branches: - main pull_request: branches: - main workflow_dispatch: jobs: # actoion이 시작될 경우 진행될 과정 build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Install Python 3 uses: actions/setup-python@v1 with: python-version: 3.9 - name: Install dependencies run: | python -m pip install --upgrade pip pip install -r requirements.txt - name: Run tests with pytest run: pytest
Actions에 발생되는 오류들
오류_1
pytest를 진행하기 위해 필요한 패키지에 대한 정보가 필요하다는 오류였다.
아래 코드를 입력하여 'requirments.txt' 파일을 생성하면 해결된다.
attrs==21.4.0 iniconfig==1.1.1 packaging==21.3 pluggy==1.0.0 py==1.11.0 pyparsing==3.0.8 pytest==7.1.2 tomli==2.0.1
오류_2
해당 레파지토리에 test를 진행하기에 적절한 파일이 없다는 오류였다.
아래의 코드와 같이 test 코드가 포함된 파일을 추가 시키면 정상 작동된다.
# test_capitalize.py def capitalize_string(s): if not isinstance(s, str): raise TypeError('Please provide a string') return s.capitalize() # 테스트코드 def test_capitalize_string(): assert capitalize_string('test') == 'Test'
'기타' 카테고리의 다른 글
[Python][Streamlit] 데이터 기반 어플 제작 1 (0) 2022.05.26 [Github] Github 홈 화면 commit graph 그리기 (0) 2022.04.12