현재 테스트 모듈로 pytest를 사용하고, IDE는 vscode를 사용하고 있는데
repository를 새로 받아서 유닛테스트를 돌리려고 하면 항상 moduleNotFoundError
가 발생했다.
매번 발생할 때마다 검색하는게 너무 귀찮아서 간단하게 정리를 위한 기록.
run and debug 탭에서 현재 파일을 실행하는 옵션을 주고, 톱니바퀴를 누르면 설정 파일이(/.vscode/launch.json) 다음과 같이 열린다.
아마 처음에 아무 설정도 하지 않았다면 cwd
와 env
는 없을텐데 이 부분을 아래에서 복사해서 추가해 주면 될 것이다.
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"cwd": "${workspaceRoot}",
"env": {"PYTHONPATH": "${workspaceRoot}"},
"console": "integratedTerminal"
}
]
}
필자의 경우에는 이 방식으로 pytest를 문제 없이 돌릴 수 있었는데 PATH 관련 문제라 100% 해결할 수 있는지는 확실하지 않다.