Skip to content

Commit 7c8264b

Browse files
authored
Updated linting tooling (#2350)
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.
1 parent 4f773a1 commit 7c8264b

File tree

7 files changed

+30
-24
lines changed

7 files changed

+30
-24
lines changed

.github/dependabot.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ updates:
1212
- dependency-name: pytest
1313
versions:
1414
- "> 3.7.3"
15+
- dependency-name: flake8 # Later versions dropped Python 2 support
16+
versions:
17+
- "> 5.0.4"
18+
- dependency-name: jsonschema # Later versions dropped Python 2 support
19+
versions:
20+
- "> 3.2.0"
1521
- dependency-name: pytest-cov
1622
versions:
1723
- "> 2.8.1"
@@ -43,6 +49,6 @@ updates:
4349
open-pull-requests-limit: 10
4450
- package-ecosystem: "github-actions"
4551
directory: "/"
46-
schedule:
52+
schedule:
4753
interval: weekly
4854
open-pull-requests-limit: 10

linter-requirements.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
mypy==1.5.1
2-
black==23.7.0
3-
flake8==5.0.4
1+
mypy
2+
black
3+
flake8==5.0.4 # flake8 depends on pyflakes>=3.0.0 and this dropped support for Python 2 "# type:" comments
44
types-certifi
55
types-redis
66
types-setuptools
77
pymongo # There is no separate types module.
88
loguru # There is no separate types module.
9-
flake8-bugbear==22.12.6
10-
pep8-naming==0.13.2
9+
flake8-bugbear
10+
pep8-naming
1111
pre-commit # local linting

tests/integrations/celery/test_celery.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ def dummy_task(self):
375375
# Curious: Cannot use delay() here or py2.7-celery-4.2 crashes
376376
res = dummy_task.apply_async()
377377

378-
with pytest.raises(Exception):
378+
with pytest.raises(Exception): # noqa: B017
379379
# Celery 4.1 raises a gibberish exception
380380
res.wait()
381381

tests/integrations/logging/test_logging.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,11 @@ def test_logging_captured_warnings(sentry_init, capture_events, recwarn):
185185
events = capture_events()
186186

187187
logging.captureWarnings(True)
188-
warnings.warn("first")
189-
warnings.warn("second")
188+
warnings.warn("first", stacklevel=2)
189+
warnings.warn("second", stacklevel=2)
190190
logging.captureWarnings(False)
191191

192-
warnings.warn("third")
192+
warnings.warn("third", stacklevel=2)
193193

194194
assert len(events) == 2
195195

tests/integrations/stdlib/test_httplib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def test_httplib_misuse(sentry_init, capture_events, request):
114114

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

117-
with pytest.raises(Exception):
117+
with pytest.raises(Exception): # noqa: B017
118118
# This raises an exception, because we didn't call `getresponse` for
119119
# the previous request yet.
120120
#

tests/integrations/wsgi/test_wsgi.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,21 +126,21 @@ def test_transaction_with_error(
126126
sentry_init, crashing_app, capture_events, DictionaryContaining # noqa:N803
127127
):
128128
def dogpark(environ, start_response):
129-
raise Exception("Fetch aborted. The ball was not returned.")
129+
raise ValueError("Fetch aborted. The ball was not returned.")
130130

131131
sentry_init(send_default_pii=True, traces_sample_rate=1.0)
132132
app = SentryWsgiMiddleware(dogpark)
133133
client = Client(app)
134134
events = capture_events()
135135

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

139139
error_event, envelope = events
140140

141141
assert error_event["transaction"] == "generic WSGI request"
142142
assert error_event["contexts"]["trace"]["op"] == "http.server"
143-
assert error_event["exception"]["values"][0]["type"] == "Exception"
143+
assert error_event["exception"]["values"][0]["type"] == "ValueError"
144144
assert error_event["exception"]["values"][0]["mechanism"]["type"] == "wsgi"
145145
assert error_event["exception"]["values"][0]["mechanism"]["handled"] is False
146146
assert (
@@ -189,14 +189,14 @@ def test_has_trace_if_performance_enabled(
189189
):
190190
def dogpark(environ, start_response):
191191
capture_message("Attempting to fetch the ball")
192-
raise Exception("Fetch aborted. The ball was not returned.")
192+
raise ValueError("Fetch aborted. The ball was not returned.")
193193

194194
sentry_init(traces_sample_rate=1.0)
195195
app = SentryWsgiMiddleware(dogpark)
196196
client = Client(app)
197197
events = capture_events()
198198

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

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

228228
sentry_init()
229229
app = SentryWsgiMiddleware(dogpark)
230230
client = Client(app)
231231
events = capture_events()
232232

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

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

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

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

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

299-
with pytest.raises(Exception):
299+
with pytest.raises(ValueError):
300300
client.get(
301301
"http://dogs.are.great/sit/stay/rollover/",
302302
headers={"sentry-trace": sentry_trace_header},

tests/test_crons.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def test_decorator_error(sentry_init):
6161
with mock.patch(
6262
"sentry_sdk.crons.decorator.capture_checkin"
6363
) as fake_capture_checking:
64-
with pytest.raises(Exception):
64+
with pytest.raises(ZeroDivisionError):
6565
result = _break_world("Grace")
6666

6767
assert "result" not in locals()
@@ -109,7 +109,7 @@ def test_contextmanager_error(sentry_init):
109109
with mock.patch(
110110
"sentry_sdk.crons.decorator.capture_checkin"
111111
) as fake_capture_checking:
112-
with pytest.raises(Exception):
112+
with pytest.raises(ZeroDivisionError):
113113
result = _break_world_contextmanager("Grace")
114114

115115
assert "result" not in locals()

0 commit comments

Comments
 (0)