본문 바로가기

pytest3

[vscode] python 환경설정 vscode 에서 python, pytest, pylint 등을 설정하면서 생긴 파일들이다. 일단 나의 기억에 도움이 되고자 아래에 적는다. 프로젝트 디렉토리 아래에서 .env PYTHONPATH=src VSCode 내에서 src 와 test 디렉토리가 나뉘어져 있을 때 src 디렉토리를 인식하기 위해서 필요했던 것으로 기억한다. .pylintrc $ pylint --generate-rcfile 기본적으로 위 명령어를 이용해서 만든다. 그런 다음 pylint 에서 src 등을 못 찾아서 경고등을 낼 수 있으므로 .pylintrc 내 init-hook='import sys; sys.path.append("./")' 에서 그러한 디렉토리들을 import 해준다. 그리고 무시하고 싶은 경고들은 disable .. 2021. 11. 5.
pytest 에서 code coverage 사용: 얼만큼 코드에 대해서 테스트를 하는가 확인. python unit test 를 pytest 로 이용할 때 내가 만든 스크립트에 대해서 test code 들이 모두 다 커버하고 있는지 확인할 필요가 있다. 이때는 pytest-cov 를 사용한다. 참조: Reporting — pytest-cov 2.11.1 documentation Reporting It is possible to generate any combination of the reports for a single test run. The available reports are terminal (with or without missing line numbers shown), HTML, XML and annotated source code. The terminal report without l.. 2021. 3. 25.
pytest 사용시 PYTHONPATH=. 설정 방법 작업환경: Ubuntu 디렉토리 구조 . ├── src │ ├── __init__.py │ └── foo.py └── test └── test_foo.py 위와 같은 구조에서 아래와 같이 pytest 를 하면 바로 에러가 발생한다. $ pytest test/ =============================================================================================== test session starts =============================================================================================== platform linux -- Python 3.8.5, pytest-6... 2021. 3. 25.