Skip to content

Return non-zero exit code from tox config when exceptions occur#3683

Merged
gaborbernat merged 2 commits intotox-dev:mainfrom
veeceey:fix/issue-3649-config-exit-code
Feb 14, 2026
Merged

Return non-zero exit code from tox config when exceptions occur#3683
gaborbernat merged 2 commits intotox-dev:mainfrom
veeceey:fix/issue-3649-config-exit-code

Conversation

@veeceey
Copy link
Copy Markdown
Contributor

@veeceey veeceey commented Feb 13, 2026

Noticed that tox config -e py47 returns exit code 0 even though the output is full of exception markers for the missing interpreter. Meanwhile tox -e py47 run correctly returns 255.

This updates the config command to return exit code -1 (255) when any config values raise exceptions during display, making it consistent with how run handles the same scenario.

Before:

$ tox -e py47 config
[testenv:py47]
...
env_site_packages_dir = # Exception: RuntimeError(...)
...
$ echo $?
0

After:

$ tox -e py47 config
[testenv:py47]
...
env_site_packages_dir = # Exception: RuntimeError(...)
...
$ echo $?
255

The change is minimal -- print_conf now returns a boolean indicating whether any exceptions occurred, and show_config uses that to decide the exit code.

Fixes #3649

When `tox config -e <env>` encounters exceptions (e.g. missing
interpreter), it now returns exit code -1 (255) instead of always
returning 0. This makes the config command consistent with the run
command which already returns 255 for skipped environments.

Fixes tox-dev#3649
@veeceey veeceey requested a review from gaborbernat as a code owner February 13, 2026 08:57
gaborbernat
gaborbernat previously approved these changes Feb 13, 2026
@gaborbernat
Copy link
Copy Markdown
Member

You will need to fix all the CI failures.

Update tests that were asserting success when tox config encounters
exceptions to now expect exit code -1. Also add towncrier changelog
fragment.
@veeceey
Copy link
Copy Markdown
Contributor Author

veeceey commented Feb 14, 2026

Thanks for the review and the approval! Just pushed a fix for the CI failures - the existing tests that run tox c on configs with intentional errors (circular set_env, base_python conflicts, pass_env whitespace) were asserting assert_success() which now correctly returns -1 with this change. Updated those test expectations accordingly.

Also added a towncrier changelog fragment for the Timeline protection check.

@gaborbernat gaborbernat merged commit 64012d4 into tox-dev:main Feb 14, 2026
51 of 53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tox config -e pyXX gives useless results if XX is invalid

2 participants