You can define default arguments for the test command by setting the default-args option, which must be an array of strings. The following is the default configuration:
You can define extra internal arguments for test scripts by setting the extra-args option, which must be an array of strings. For example, if you wanted to increase the verbosity of pytest, you could set the following:
If you want to change the default commands that are executed, you can override the scripts. The following default scripts must be redefined:
[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"
The run script is the default behavior while the run-cov script is used instead when measuring code coverage. The cov-combine script runs after all tests complete when measuring code coverage, as well as the cov-report script when not using the --cover-quiet flag.
Note
The HATCH_TEST_ARGS environment variable is how the test command's flags are translated and internally populated without affecting the user's arguments. This is also the way that extra arguments are passed.