pytest-dev / pytest-dev/pytest

Unhandled exceptions in `pytest_unconfigure` hooks exit `1` and not `3` - `ExitCode.INTERNAL_ERROR`

Open
#9,808 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic: config type: refactoring
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

Hi, as (briefly) discussed in this discussion, pytest_unconfigure differs from pytest_configure in terms of exiting.

When a pytest_configure(...) implementation raises an unhandled exception; pytest exits 3 - ExitCode.INTERNAL_ERROR; this is outlined below:

# conftest.py
import pytest

@pytest.hookimpl
def pytest_configure(config: pytest.Config):
    raise Exception("Unhandled exception; exit will be 3.")

# test_foo.py

def test_foo():
    assert True
pytest .
echo $?
3

However; the reverse is not true, an unhandled exception in the pytest_unconfigure(...) cases forces pytest to exit 1 instead.

# conftest.py
import pytest

@pytest.hookimpl
def pytest_configure(config: pytest.Config) -> None:
    raise Exception("Unhandled exc; exit will be 3.")


@pytest.hookimpl
def pytest_unconfigure(config: pytest.Config) -> None:
    raise Exception("No internal error here; pytest will exit 1")

# test_foo.py

def test_foo():
    assert True

and a 1 exit code:

    raise Exception("No internal error here; pytest will exit 1")
Exception: No internal error here; pytest will exit 1
(venv)  ✘ sy  ~/PycharmProjects/pythonProject45  echo $?
1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue using the conftest.py and test_foo.py examples, comparing pytest_configure and pytest_unconfigure exception handling and their exit codes. Trace the hook handling and add a regression test showing that an unhandled pytest_unconfigure exception exits with ExitCode.INTERNAL_ERROR (3), then run the relevant test suite.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.