Repository navigation
ci(ruff): Enable PT012 for pytest.raises() blocks with several statements - #8287
Closed
sentry-junior[bot] wants to merge 2 commits into
Closed
sentry-junior[bot] wants to merge 2 commits into
sentry-junior[bot] wants to merge 2 commits into
Conversation
sentry-junior
Bot
force-pushed
the
ci/ruff-pytest-raises-too-broad
branch
from
November 16, 2026 09:52
7fe277b to
f798939
Compare
sentry-junior
Bot
force-pushed
the
ci/ruff-pytest-raises-multiple-statements
branch
from
November 16, 2026 09:52
134ce8f to
4f933e1
Compare
…ents Existing cases get a noqa comment, so only new tests are checked. Co-Authored-By: Ivana Kellyer <131587164+sentrivana@users.noreply.github.com>
sentry-junior
Bot
changed the base branch from
ci/ruff-pytest-raises-too-broad
to
master
November 16, 2026 10:03
sentry-junior
Bot
force-pushed
the
ci/ruff-pytest-raises-multiple-statements
branch
from
November 16, 2026 10:03
4f933e1 to
bb31f9b
Compare
This was referenced Nov 16, 2026
sentrivana
added a commit
that referenced
this pull request
Nov 16, 2026
### Description Turns on ruff's `T20`, which flags `print()` and `pprint()` calls. The SDK runs inside users' apps, so a stray debug `print()` ends up in their output; we should log through the SDK logger instead. `sentry_sdk` has none today, so this is config only. Tests and scripts are excluded via `per-file-ignores` because they print on purpose. Each ruff-rule PR (#8282, #8283, #8285, #8286, #8287) targets `master` on its own. They all add a line to the same `select` list in `pyproject.toml`, so whichever merges first leaves the others with a small conflict there to resolve. <!-- junior-request-attribution:start --> via @sentrivana. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:slack%3AC0CAA8NNBE3%3A1794392136.309249 --> -- [View Session](https://junior-prod.sentry.dev/conversations/slack%3AC0CAA8NNBE3%3A1794392136.309249) [[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0CAA8NNBE3%3A1794392136.309249/?project=4510944073809921) <!-- junior-session-footer:end --> Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Ivana Kellyer <131587164+sentrivana@users.noreply.github.com>
Contributor
Coverage Results 📊✅ 139266 passed | ⏭️ 7853 skipped | Total: 147119 | Pass Rate: 94.66% | Execution Time: 445m 54s All tests are passing successfully. ✅ Patch coverage is 100.00% (no changed executable lines found; target 80%). Coverage diff@@ Coverage Diff @@
## master #8287 +/-##
==========================================
Coverage 90.21% 90.21% —%
==========================================
Files 203 203 —
Tracked lines 27335 27335 —
Branches 10246 10246 —
==========================================
- Hits 24661 24660 -1
- Misses 2674 2675 +1
- Partials 1558 1559 +1Generated by Coverage Action |
…es-multiple-statements # Conflicts: # pyproject.toml
sentrivana
marked this pull request as ready for review
November 16, 2026 10:23
sentrivana
marked this pull request as draft
November 16, 2026 10:23
sentrivana
added a commit
that referenced
this pull request
Nov 16, 2026
### Description Turns on ruff's `PT011`, which flags `pytest.raises()` with a broad exception type such as `ValueError` or `Exception` and no `match=`. Without `match=`, a test can pass on the wrong error. The 27 existing offenders are fixed rather than ignored. Most get a `match=` with the expected message. Two get a narrower exception type (`CannotSendRequest` in the httplib test, `ZeroDivisionError` in a skipped celery test), and `test_get_error_message` no longer misuses `pytest.raises()` as an attribute holder. Each ruff-rule PR (#8282, #8283, #8285, #8286, #8287) targets `master` on its own. They all add a line to the same `select` list in `pyproject.toml`, so whichever merges first leaves the others with a small conflict there to resolve. <!-- junior-request-attribution:start --> via @sentrivana. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:slack%3AC0CAA8NNBE3%3A1794392136.309249 --> -- [View Session](https://junior-prod.sentry.dev/conversations/slack%3AC0CAA8NNBE3%3A1794392136.309249) [[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0CAA8NNBE3%3A1794392136.309249/?project=4510944073809921) <!-- junior-session-footer:end --> --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Ivana Kellyer <131587164+sentrivana@users.noreply.github.com> Co-authored-by: Ivana Kellyer <ivana.kellyer@sentry.io>
sentrivana
added a commit
that referenced
this pull request
Nov 16, 2026
### Description Turns on ruff's `RUF100`, which flags `noqa` comments that don't suppress anything, so stale suppressions can't pile up. It also removes the 189 that exist today, most of them `N8xx`, `E231` and `B0xx` codes left over from the flake8 plugins, which ruff doesn't enable here. The leftover `B`/`N` ignores and notes in `pyproject.toml` go too. Only comments and config change; some lines got joined by `ruff format` once their comments were gone. Each ruff-rule PR (#8282, #8283, #8285, #8286, #8287) targets `master` on its own. They all add a line to the same `select` list in `pyproject.toml`, so whichever merges first leaves the others with a small conflict there to resolve. <!-- junior-request-attribution:start --> via @sentrivana. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:slack%3AC0CAA8NNBE3%3A1794392136.309249 --> -- [View Session](https://junior-prod.sentry.dev/conversations/slack%3AC0CAA8NNBE3%3A1794392136.309249) [[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0CAA8NNBE3%3A1794392136.309249/?project=4510944073809921) <!-- junior-session-footer:end --> --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Ivana Kellyer <131587164+sentrivana@users.noreply.github.com>
sentrivana
added a commit
that referenced
this pull request
Nov 16, 2026
### Description Turns on ruff's `PLC0415`, which flags imports that aren't at the top level of the file. This enforces the top-level-imports guideline in `AGENTS.md`, which reviewers currently check by hand. The rule covers `sentry_sdk` only; tests are excluded. 16 existing inline imports didn't need to be inline, so they're now at the top level or in an existing module-level import. The other 89 are intentional (optional deps, version checks, circular imports, Django) and get a `# noqa: PLC0415` comment, so any new inline import needs the same explicit marker. Each ruff-rule PR (#8282, #8283, #8285, #8286, #8287) targets `master` on its own. They all add a line to the same `select` list in `pyproject.toml`, so whichever merges first leaves the others with a small conflict there to resolve. <!-- junior-request-attribution:start --> via @sentrivana. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:slack%3AC0CAA8NNBE3%3A1794392136.309249 --> -- [View Session](https://junior-prod.sentry.dev/conversations/slack%3AC0CAA8NNBE3%3A1794392136.309249) [[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC0CAA8NNBE3%3A1794392136.309249/?project=4510944073809921) <!-- junior-session-footer:end --> --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Ivana Kellyer <131587164+sentrivana@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Turns on ruff's
PT012, which flagspytest.raises()blocks with more than one statement. In such a block an earlier line can raise the expected exception, and the test passes without exercising the line it's meant to check.The 39 existing cases in tests get a
# noqa: PT012comment, so only new tests are checked.Each ruff-rule PR (#8282, #8283, #8285, #8286, #8287) targets
masteron its own. They all add a line to the sameselectlist inpyproject.toml, so whichever merges first leaves the others with a small conflict there to resolve.via @sentrivana.
--
View Session [Sentry]