pytest-dev / pytest-dev/pytest

mypy plugin to ignore type-checking errors with pytest.raises

Open
#8,984 7 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

status: help wanted
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

When writing tests for error cases using with pytest.raises(...), the code within the body will always generate a mypy error which must be ignored (if a project has sufficient static typing).

It would be great if pytest included a mypy plugin which can suppress the errors in these cases.

Example:
https://github.com/aio-libs/aiohttp-session/blob/5f0ffbd7932e2ee256e0fb0ae4cdcad50d73cddc/tests/test_redis_storage.py#L346

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

Start by reviewing the linked aiohttp-session test example and the requested pytest.raises behavior. Determine the integration points needed for a mypy plugin, and consider the work done when errors inside pytest.raises blocks are suppressed without hiding unrelated type-checking errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.