_pytest.warnings module

_setoption(wmod, arg)[source]

Copy of the warning._setoption function but does not escape arguments.

pytest_addoption(parser)[source]
pytest_configure(config)[source]
with catch_warnings_for_item(config, ihook, when, item)[source]

Context manager that catches warnings generated in the contained execution block.

item can be None if we are not in the context of an item execution.

Each warning captured triggers the pytest_warning_captured hook.

for ... in pytest_runtest_protocol(item)[source]
for ... in pytest_collection(session: _pytest.main.Session) → Generator[None, None, None][source]
for ... in pytest_terminal_summary(terminalreporter)[source]
for ... in pytest_sessionfinish(session)[source]
_issue_warning_captured(warning, hook, stacklevel)[source]

This function should be used instead of calling warnings.warn directly when we are in the “configure” stage: at this point the actual options might not have been set, so we manually trigger the pytest_warning_captured hook so we can display these warnings in the terminal. This is a hack until we can sort out #2891.

Parameters
  • warning – the warning instance.

  • hook – the hook caller

  • stacklevel – stacklevel forwarded to warnings.warn