Testing configuration¶
より包括的なウォークスルーについては、testing overview tutorialを参照してください。
Settings¶
オプションに対応するtest
コマンドフラグがある場合、そのフラグが常に優先されます。
Default arguments¶
test
コマンドのデフォルトの引数を定義するには、default-args
オプションを設定します。このオプションは文字列の配列である必要があります。デフォルト設定は次のとおりです。:
[tool.hatch.envs.hatch-test]
default-args = ["tests"]
[envs.hatch-test]
default-args = ["tests"]
Extra arguments¶
testscriptsに追加の内部引数を定義するには、文字列の配列であるextra-args
オプションを設定します。たとえば、pytest
の冗長性を高めるには、次のように設定します。:
[tool.hatch.envs.hatch-test]
extra-args = ["-vv"]
[envs.hatch-test]
extra-args = ["-vv"]
Randomize test order¶
--randomize
/-r
フラグに対応するrandomize
オプションを有効にすることで、テストの順序をrandomizeすることができます。:
[tool.hatch.envs.hatch-test]
randomize = true
[envs.hatch-test]
randomize = true
Parallelize test execution¶
--parallel
/-p
フラグに対応するparallel
オプションを有効にすることで、parallelizeテストを実行できます。:
[tool.hatch.envs.hatch-test]
parallel = true
[envs.hatch-test]
parallel = true
Retry failed tests¶
--retries
フラグに対応するretries
オプションを設定することで、失敗したテストをretryすることができます。:
[tool.hatch.envs.hatch-test]
retries = 2
[envs.hatch-test]
retries = 2
--retry-delay
フラグに対応するretry-delay
オプションを設定することで、再試行の間に待機する秒数を設定することもできます。:
[tool.hatch.envs.hatch-test]
retry-delay = 1
[envs.hatch-test]
retry-delay = 1
Customize environment¶
test
コマンドで使用される環境の動作を完全に変更できます。
Dependencies¶
テストに必要なextra dependenciesを定義できます。:
[tool.hatch.envs.hatch-test]
extra-dependencies = [
"pyfakefs",
"pytest-asyncio",
"pytest-benchmark",
"pytest-memray",
"pytest-playwright",
"pytest-print",
]
[envs.hatch-test]
extra-dependencies = [
"pyfakefs",
"pytest-asyncio",
"pytest-benchmark",
"pytest-memray",
"pytest-playwright",
"pytest-print",
]
次に、デフォルト設定を示します。:
[tool.hatch.envs.hatch-test]
dependencies = [
"coverage-enable-subprocess==1.0",
"coverage[toml]~=7.4",
"pytest~=8.1",
"pytest-mock~=3.12",
"pytest-randomly~=3.15",
"pytest-rerunfailures~=14.0",
"pytest-xdist[psutil]~=3.5",
]
[envs.hatch-test]
dependencies = [
"coverage-enable-subprocess==1.0",
"coverage[toml]~=7.4",
"pytest~=8.1",
"pytest-mock~=3.12",
"pytest-randomly~=3.15",
"pytest-rerunfailures~=14.0",
"pytest-xdist[psutil]~=3.5",
]
Matrix¶
デフォルトの一連のmatricesは上書きできます。:
[[tool.hatch.envs.hatch-test.matrix]]
python = ["3.12", "3.11", "3.10", "3.9", "3.8"]
[[envs.hatch-test.matrix]]
python = ["3.12", "3.11", "3.10", "3.9", "3.8"]
Scripts¶
実行されるデフォルト・コマンドを変更する場合は、scriptsを上書きできます。次のデフォルト・スクリプトを再定義する必要があります:
[tool.hatch.envs.hatch-test.scripts]
run = "pytest{env:HATCH_TEST_ARGS:} {args}"
run-cov = "coverage run -m pytest{env:HATCH_TEST_ARGS:} {args}"
cov-combine = "coverage combine"
cov-report = "coverage report"
[envs.hatch-test.scripts]
run = "pytest{env:HATCH_TEST_ARGS:} {args}"
run-cov = "coverage run -m pytest{env:HATCH_TEST_ARGS:} {args}"
cov-combine = "coverage combine"
cov-report = "coverage report"
run
スクリプトはデフォルトの動作ですが、コードカバレッジを測定する場合は代わりにrun-cov
スクリプトが使用されます。コードカバレッジを測定する場合はすべてのテストが完了した後にcov-combine
スクリプトが実行され、--cover-quiet
フラグを使用しない場合はcov-report
スクリプトが実行されます。
Note
HATCH_TEST_ARGS
環境変数は、ユーザの引数に影響を与えることなく、test
コマンドのフラグが変換され、内部的に入力される方法です。これは、extra argumentsが渡される方法でもあります。
Installer¶
既定では、UV is enabledです。この動作を無効にするには、次の手順を実行します。:
[tool.hatch.envs.hatch-test]
installer = "pip"
[envs.hatch-test]
installer = "pip"