vscode python setup

x·2022년 8월 5일
0

vscode

목록 보기
1/1

vscode(code editor)는 pycharm(python IDE) 유료 버전에 비해서 초기에 갖춰진 게 없다. auto complete, intellisense, snippet, debug 등을 초기엔 사용할 수 없다.

extension

vscode에 블럭 모양을 클릭하면 확장 프로그램을 설치할 수 있다.

python extension
break point, snippet 등 사용 가능

arepl
코드 실행 없이 실시간으로 사용된 변수, 결과를 볼 수 있음

우측 상단 캐릭터 클릭

tabnine
autocompletion, docs

python인데 ;를 붙이라고 한다...

제안해주는 것을 채택하려면 tab을 누르고 단어 단위로 채택하려면 command -> 누르면 됨

settings.json에
"python.languageServer": "Pylance"

	"python.languageServer": "Pylance",
    "python.analysis.autoImportCompletions": true,
    "python.analysis.typeCheckingMode": "basic",
    "python.analysis.inlayHints.variableTypes": true,
    "python.analysis.inlayHints.functionReturnTypes": true,
    "python.analysis.inlayHints.callArgumentNames": "all",
    "python.analysis.autoFormatStrings": true,
    "python.analysis.autoSearchPaths": true,

    "python.analysis.enablePytestSupport": true,
    "python.analysis.inlayHints.pytestParameters": true,

python test exploer

pytest
설정에서 pytest enabled 체크

testing 버튼이 생김, 테스트를 각 메서드마다 할 수 있음

python test explorer for visual studio code

test explorer 사용 시 env file 지정하는 방법
python.envFile 에 env 파일 경로 지정

{
    "python.autoComplete.extraPaths": [],
    "python.analysis.autoImportCompletions": true,
    "python.analysis.extraPaths": [],
    "python.defaultInterpreterPath": "/Users/simon/Library/Caches/pypoetry/virtualenvs/xxx-dXiQi3sf-py3.9/bin/python",
    // test
    "python.testing.pytestArgs": [
        "flask/app"
    ],
    "python.testing.unittestEnabled": false,
    "python.testing.pytestEnabled": true,
    "pythonTestExplorer.testFramework": "pytest",
    "python.testing.autoTestDiscoverOnSaveEnabled": true,
    "files.exclude": {
        "**/*.pyc": {
            "when": "$(basename).py"
        },
        "**/__pycache__": true,
        ".pytest_cache": true,
    },
    "python.formatting.provider": "black",
    "editor.formatOnSave": true,
    "editor.formatOnType": true,
    "python.envFile": "${workspaceFolder}/.test.env",
}

terminal에서 pytest 실행 시 env file 적용하는 방법
pytest.ini 파일 생성

[pytest]
env_files =
    .test.env
filterwarnings =
    ignore::DeprecationWarning

기타

pycache 생성 안하도록 환경변수 지정
export PYTHONDONTWRITEBYTECODE=1
vscode에 파일 지정

{
    "files.exclude": {
        "**/*.pyc": {"when": "$(basename).py"},
        "**/__pycache__": true,
    }
}

출처

0개의 댓글