Python プロジェクトの作成
hikari edited this page Mar 6, 2022
·
11 revisions
Poetry のインストール
python -m pip install --upgrade pip
python -m pip install poetry
テンプレートの生成
poetry new PROJECT_NAME
pytest
にバグがあるらしいので、書き換えておく。(https://stackoverflow.com/questions/69528842/an-error-while-trying-to-execute-tests-on-python-3-10-with-pytest)
E TypeError: required field "lineno" missing from alias
=================================================================== short test summary info ===================================================================
ERROR tests/test_xxxxx.py - TypeError: required field "lineno" missing from alias
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
====================================================================== 1 error in 0.12s =======================================================================
[tool.poetry.dev-dependencies]
- pytest = "^5.2"
+ pytest = "^7.0.1"
依存パッケージの追加
poetry add PIP_PACKAGE
flake8 のインストール flake8 が
pyproject.toml
に対応していないので、pyproject-flake8
をインストールする (将来的にできるようになるかも。)
poetry add -D pyproject-flake8
autopep8 のインストール フォーマッタ。
poetry add -D autopep8
パッケージのアップデート
poetry update
poetry config virtualenvs.in-project true
Ctrl
+ Shift
+ P
で "Python: Select Interpreter" を選択し、Poetry のものを選ぶ。
poetry run python xxxxx/xxxxx.py
tests/test_xxxxx.py
にテストコードを記述し以下を実行。
poetry run pytest
poetry build