Skip to content

Commit

Permalink
Updated linting tooling (#2350)
Browse files Browse the repository at this point in the history
Removed the pins to some of our linting tools to make sure we have the newest tools. (But pinning `flake8` because later versions dropped Python 2 support)

Also fixed some problems the new tools showed.

Also made sure that dependabot does not bug us about `flake8` and `jsonschema` anymore.
  • Loading branch information
antonpirker authored Sep 6, 2023
1 parent 4f773a1 commit 7c8264b
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 24 deletions.
8 changes: 7 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ updates:
- dependency-name: pytest
versions:
- "> 3.7.3"
- dependency-name: flake8 # Later versions dropped Python 2 support
versions:
- "> 5.0.4"
- dependency-name: jsonschema # Later versions dropped Python 2 support
versions:
- "> 3.2.0"
- dependency-name: pytest-cov
versions:
- "> 2.8.1"
Expand Down Expand Up @@ -43,6 +49,6 @@ updates:
open-pull-requests-limit: 10
- package-ecosystem: "github-actions"
directory: "/"
schedule:
schedule:
interval: weekly
open-pull-requests-limit: 10
10 changes: 5 additions & 5 deletions linter-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
mypy==1.5.1
black==23.7.0
flake8==5.0.4
mypy
black
flake8==5.0.4 # flake8 depends on pyflakes>=3.0.0 and this dropped support for Python 2 "# type:" comments
types-certifi
types-redis
types-setuptools
pymongo # There is no separate types module.
loguru # There is no separate types module.
flake8-bugbear==22.12.6
pep8-naming==0.13.2
flake8-bugbear
pep8-naming
pre-commit # local linting
2 changes: 1 addition & 1 deletion tests/integrations/celery/test_celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ def dummy_task(self):
# Curious: Cannot use delay() here or py2.7-celery-4.2 crashes
res = dummy_task.apply_async()

with pytest.raises(Exception):
with pytest.raises(Exception): # noqa: B017
# Celery 4.1 raises a gibberish exception
res.wait()

Expand Down
6 changes: 3 additions & 3 deletions tests/integrations/logging/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ def test_logging_captured_warnings(sentry_init, capture_events, recwarn):
events = capture_events()

logging.captureWarnings(True)
warnings.warn("first")
warnings.warn("second")
warnings.warn("first", stacklevel=2)
warnings.warn("second", stacklevel=2)
logging.captureWarnings(False)

warnings.warn("third")
warnings.warn("third", stacklevel=2)

assert len(events) == 2

Expand Down
2 changes: 1 addition & 1 deletion tests/integrations/stdlib/test_httplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def test_httplib_misuse(sentry_init, capture_events, request):

conn.request("GET", "/200")

with pytest.raises(Exception):
with pytest.raises(Exception): # noqa: B017
# This raises an exception, because we didn't call `getresponse` for
# the previous request yet.
#
Expand Down
22 changes: 11 additions & 11 deletions tests/integrations/wsgi/test_wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,21 +126,21 @@ def test_transaction_with_error(
sentry_init, crashing_app, capture_events, DictionaryContaining # noqa:N803
):
def dogpark(environ, start_response):
raise Exception("Fetch aborted. The ball was not returned.")
raise ValueError("Fetch aborted. The ball was not returned.")

sentry_init(send_default_pii=True, traces_sample_rate=1.0)
app = SentryWsgiMiddleware(dogpark)
client = Client(app)
events = capture_events()

with pytest.raises(Exception):
with pytest.raises(ValueError):
client.get("http://dogs.are.great/sit/stay/rollover/")

error_event, envelope = events

assert error_event["transaction"] == "generic WSGI request"
assert error_event["contexts"]["trace"]["op"] == "http.server"
assert error_event["exception"]["values"][0]["type"] == "Exception"
assert error_event["exception"]["values"][0]["type"] == "ValueError"
assert error_event["exception"]["values"][0]["mechanism"]["type"] == "wsgi"
assert error_event["exception"]["values"][0]["mechanism"]["handled"] is False
assert (
Expand Down Expand Up @@ -189,14 +189,14 @@ def test_has_trace_if_performance_enabled(
):
def dogpark(environ, start_response):
capture_message("Attempting to fetch the ball")
raise Exception("Fetch aborted. The ball was not returned.")
raise ValueError("Fetch aborted. The ball was not returned.")

sentry_init(traces_sample_rate=1.0)
app = SentryWsgiMiddleware(dogpark)
client = Client(app)
events = capture_events()

with pytest.raises(Exception):
with pytest.raises(ValueError):
client.get("http://dogs.are.great/sit/stay/rollover/")

msg_event, error_event, transaction_event = events
Expand All @@ -223,14 +223,14 @@ def test_has_trace_if_performance_disabled(
):
def dogpark(environ, start_response):
capture_message("Attempting to fetch the ball")
raise Exception("Fetch aborted. The ball was not returned.")
raise ValueError("Fetch aborted. The ball was not returned.")

sentry_init()
app = SentryWsgiMiddleware(dogpark)
client = Client(app)
events = capture_events()

with pytest.raises(Exception):
with pytest.raises(ValueError):
client.get("http://dogs.are.great/sit/stay/rollover/")

msg_event, error_event = events
Expand All @@ -248,7 +248,7 @@ def test_trace_from_headers_if_performance_enabled(
):
def dogpark(environ, start_response):
capture_message("Attempting to fetch the ball")
raise Exception("Fetch aborted. The ball was not returned.")
raise ValueError("Fetch aborted. The ball was not returned.")

sentry_init(traces_sample_rate=1.0)
app = SentryWsgiMiddleware(dogpark)
Expand All @@ -258,7 +258,7 @@ def dogpark(environ, start_response):
trace_id = "582b43a4192642f0b136d5159a501701"
sentry_trace_header = "{}-{}-{}".format(trace_id, "6e8f22c393e68f19", 1)

with pytest.raises(Exception):
with pytest.raises(ValueError):
client.get(
"http://dogs.are.great/sit/stay/rollover/",
headers={"sentry-trace": sentry_trace_header},
Expand Down Expand Up @@ -286,7 +286,7 @@ def test_trace_from_headers_if_performance_disabled(
):
def dogpark(environ, start_response):
capture_message("Attempting to fetch the ball")
raise Exception("Fetch aborted. The ball was not returned.")
raise ValueError("Fetch aborted. The ball was not returned.")

sentry_init()
app = SentryWsgiMiddleware(dogpark)
Expand All @@ -296,7 +296,7 @@ def dogpark(environ, start_response):
trace_id = "582b43a4192642f0b136d5159a501701"
sentry_trace_header = "{}-{}-{}".format(trace_id, "6e8f22c393e68f19", 1)

with pytest.raises(Exception):
with pytest.raises(ValueError):
client.get(
"http://dogs.are.great/sit/stay/rollover/",
headers={"sentry-trace": sentry_trace_header},
Expand Down
4 changes: 2 additions & 2 deletions tests/test_crons.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_decorator_error(sentry_init):
with mock.patch(
"sentry_sdk.crons.decorator.capture_checkin"
) as fake_capture_checking:
with pytest.raises(Exception):
with pytest.raises(ZeroDivisionError):
result = _break_world("Grace")

assert "result" not in locals()
Expand Down Expand Up @@ -109,7 +109,7 @@ def test_contextmanager_error(sentry_init):
with mock.patch(
"sentry_sdk.crons.decorator.capture_checkin"
) as fake_capture_checking:
with pytest.raises(Exception):
with pytest.raises(ZeroDivisionError):
result = _break_world_contextmanager("Grace")

assert "result" not in locals()
Expand Down

0 comments on commit 7c8264b

Please sign in to comment.